package com.ymttest.business.service.shenqi;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONObject;

import com.google.common.collect.Lists;
import com.shop2cn.iapi.shenqisettlement.parameter.OnHpSettledReq;
import com.shop2cn.iapi.shenqisettlement.parameter.SaveProxyFissionConfigReq;
import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.shenqisettlement.service.OnHpSettledCall;
import com.shop2cn.iapi.shenqisettlement.service.SaveProxyFissionConfigCall;
import com.shop2cn.iapi.sqoptrade.parameter.enums.AppTerminalSourceEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CancelOrderTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CouponApplianceTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.LogisticsTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.OrderSourceEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.ProductRefundChannelEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.PromotionTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.SalesTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.TerminalSourceEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.UserTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.req.AcceptOrderReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.AddSellerMemoReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.CancelOrderReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.ChangeOrderAddressReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.ChangeOrderDiscountReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.ConfirmApplyRefundReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.ConfirmOfflinePayReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.ConfirmReceiveReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.MarkOrderLockReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.PayReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.PlaceOrderReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.ReduceSqProductStocksReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.SqStockChangeNotifyReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.UpdateOrderDeliveryTimeReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.UpdateOrderProductSkuReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.UpdateShenQiSellerMemoReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.UpdateSqIdcardInfoReq;
import com.shop2cn.iapi.sqoptrade.parameter.req.UpdateVoucherReq;
import com.shop2cn.iapi.sqoptrade.parameter.utill.Utils;
import com.shop2cn.iapi.sqoptrade.parameter.vo.CatalogApportionVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.CouponVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderGroupVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderItemVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.PickInStoreVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.SellerPromotionVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.UbuyUserVo;
import com.shop2cn.iapi.sqoptrade.resp.Order;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.AddSellerMemoCall;
import com.shop2cn.iapi.sqoptrade.service.CancelOrderCall;
import com.shop2cn.iapi.sqoptrade.service.ChangeOrderAddressCall;
import com.shop2cn.iapi.sqoptrade.service.ChangeOrderDiscountCall;
import com.shop2cn.iapi.sqoptrade.service.ConfirmOfflinePayCall;
import com.shop2cn.iapi.sqoptrade.service.ConfirmReceiveCall;
import com.shop2cn.iapi.sqoptrade.service.MarkOrderLockCall;
import com.shop2cn.iapi.sqoptrade.service.PayReqCall;
import com.shop2cn.iapi.sqoptrade.service.PlaceOrderCall;
import com.shop2cn.iapi.sqoptrade.service.ReduceSqProductStocksCall;
import com.shop2cn.iapi.sqoptrade.service.SellerAcceptOrderCall;
import com.shop2cn.iapi.sqoptrade.service.SqStockChangeNotifyCall;
import com.shop2cn.iapi.sqoptrade.service.UpdateOrderDeliveryTimeCall;
import com.shop2cn.iapi.sqoptrade.service.UpdateOrderProductSkuCall;
import com.shop2cn.iapi.sqoptrade.service.UpdateShenQiSellerMemoCall;
import com.shop2cn.iapi.sqoptrade.service.UpdateSqIdcardInfoCall;
import com.shop2cn.iapi.sqoptrade.service.UpdateVoucherCall;
import com.shop2cn.iapi.sqrefund.parameter.FullRefundReq;
import com.shop2cn.iapi.sqrefund.service.FullRefundCall;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.activitymgt.parameter.CatalogAgentBean;
import com.shop2cn.iapi.activitymgt.parameter.ProductAgentBean;
import com.shop2cn.iapi.cdfgeteway.resp.PointsVo;
import com.shop2cn.iapi.delivery.parameter.DeliveryInfo;
import com.shop2cn.iapi.delivery.parameter.SqDeliveryReq;
import com.shop2cn.iapi.delivery.service.SqDeliveryCall;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.MchInfoVo;
import com.ymatou.iapi.godmch.parameter.MerchantFundCollectConfigReq;
import com.ymatou.iapi.godmch.parameter.MerchantFundCollectConfigResp;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.detailmchBean;
import com.ymatou.iapi.godmch.service.MerchantFundCollectConfigCall;
import com.ymatou.iapi.godmch.service.detailmchCall;
import com.ymatou.iapi.leaf.parameter.GetSeqReq;
import com.ymatou.iapi.leaf.service.GetSeqIdsCall;
//import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallServiceV2;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.Shop2cnStockCallService;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.database.model.shenqisettlement.CurrencyConfig;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.PaymentPo;
import com.ymttest.database.sharding.db.sharding.model.ShenqiProxyChainPo;
import com.ymttest.database.sharding.db.sharding.model.UserRefundFundDetailPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.database.sqlwapper.shenqisettlement.CurrencyConfigWrapper;
import com.ymttest.database.sqlwapper.shenqisettlement.OrderSettlementDetailWrapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

public class TradingForDGSQCallService {

	private static long autotest_goodsOwnerId = ShenqiUserSet.autotest_goodsOwnerId;
	private static String autotest_goodsOwnerName = String.valueOf(EnvSetup
			.getData("autotest_goodsOwnerName"));

	private static OnHpSettledReq hpSettledReq = new OnHpSettledReq();
	private static OnHpSettledCall hpSettledCall = new OnHpSettledCall();

	/**
	 * buildDGSQStandPlaceOrderReq 一个商家，一个商品，生成一个订单
	 * 
	 * @param salesman
	 *            店主的销售员
	 * @param discount
	 *            代下单时调价.大于0，加价；小于0；减价
	 * @userId userId 买家id
	 * @sellerId sellerId 买手id
	 * @sellerId sellerName 买手名称
	 * @return
	 */
	public static PlaceOrderReq buildDGSQStandPlaceOrderReq(long salesman,
			BigDecimal discount, long userId, AgentProductBean productBean,
			long goodOwnerId, boolean useCoupon, boolean supportOfflinePay) {

		PlaceOrderReq req = new PlaceOrderReq();
		req.setAddressId(772208L);
		req.setRecvMobile("136" + TestDataManager.getRandomNum(8));
		req.setRecvName("testUser");
		req.setAppId("ymt autotest");
		req.setUserId(userId);

		req.setFromShenqi(true);
		req.setSalesman(salesman);
		req.setDiscount(discount);

		req.setAddress("上海,静安,江场三路,市北高新");
		req.setPostCode("200000");

		req.setEquipmentId(TestDataManager.getRandomUUID().toString());
		req.setDeviceId(TestDataManager.getRandomUUID().toString());
		req.setSourceIp(TestDataManager.getRandomIp());

		req.setAppTerminalSource(AppTerminalSourceEnum.Phone);
		req.setOrderSource(OrderSourceEnum.Wechat);
		req.setTerminalSource(TerminalSourceEnum.Android);

		req.setMainOrderId(genMainOrderId(req.getUserId()));

		req.setSupportOfflinePay(supportOfflinePay);

		OrderVo orderVo;

		orderVo = createOrderVo(Lists.newArrayList(productBean));

		orderVo.setGoodsOwnerId(goodOwnerId);
		orderVo.setShenqiLogisticsType(999);
		orderVo.setShenqiIdCardRequirement(2);

		// 一个商家一个订单一个商品
		OrderGroupVo groupVo1 = new OrderGroupVo();

		groupVo1.setSellerId(productBean.getSellerId());
		groupVo1.setSellerLoginId(productBean.getSellerLoginId());

		groupVo1.setSellerCoupon(null);

		groupVo1.setOrders(Lists.newArrayList(orderVo));

		req.setOrderGroups(Lists.newArrayList(groupVo1));

		req.setCurrencySymbol("$");
		req.setPayChannelType(1);

		if (useCoupon) {

			long sellerId = groupVo1.getSellerId();

			// 商家券
			CouponVo sellerCoupon1 = TradingForDGSQCallService
					.createSellerCouponVo(userId, sellerId, new BigDecimal(30),
							BigDecimal.TEN);

			groupVo1.setSellerCoupon(sellerCoupon1);
		}

		return req;
	}

	public static PlaceOrderReq buildDGSQStandPlaceOrderReq(long salesman,
			BigDecimal discount, long userId, AgentProductBean productBean,
			long goodOwnerId, boolean useCoupon) {

		return buildDGSQStandPlaceOrderReq(salesman, discount, userId,
				productBean, goodOwnerId, useCoupon, false);
	}

	/**
	 * buildDGSQStandPlaceOrderReq 一个商家，一个商品，生成一个订单
	 * 
	 * @param salesman
	 *            店主的销售员
	 * @param discount
	 *            代下单时调价.大于0，加价；小于0；减价
	 * @userId userId 买家id
	 * @sellerId sellerId 买手id
	 * @sellerId sellerName 买手名称
	 * @return
	 */
	public static PlaceOrderReq buildDGSQStandPlaceOrderReq(long salesman,
			BigDecimal discount, long userId, AgentProductBean productBean,
			long goodOwnerId) {

		return buildDGSQStandPlaceOrderReq(salesman, discount, userId,
				productBean, goodOwnerId, false, false);
	}

	/**
	 * createOrderGroupVo
	 *
	 * @param goodOwnerId
	 * @return OrderGroupVo
	 */
	public static OrderGroupVo createOrderGroupVo(AgentProductBean productBean,
			long goodOwnerId) {

		OrderGroupVo groupVo = new OrderGroupVo();

		groupVo.setSellerId(productBean.getSellerId());
		groupVo.setSellerLoginId(productBean.getSellerLoginId());
		groupVo.setSellerCoupon(null);

		OrderVo orderVo = createOrderVo(Lists.newArrayList(productBean));

		orderVo.setGoodsOwnerId(goodOwnerId);
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		groupVo.setOrders(Lists.newArrayList(orderVo));

		return groupVo;
	}

	/**
	 * createOrderVo
	 * 
	 * @param agentProductBeanList
	 * @return OrderVo
	 */
	public static OrderVo createOrderVo(
			List<AgentProductBean> agentProductBeanList) {

		OrderVo order = new OrderVo();

		order.setLogisticsType(LogisticsTypeEnum.Unknown);
		order.setAutoCancelOrderHours(BigDecimal.ONE);
		order.setLeaveWord("尽快发货！");

		List<OrderItemVo> items = new ArrayList<OrderItemVo>();

		for (AgentProductBean product : agentProductBeanList) {
			items.add(createOrderItemVo(product.getProductId(), product
					.getCatalogList().get(0)));
		}

		order.setOrderItems(items);

		order.setGoodsOwnerId(agentProductBeanList.get(0).getGoodsOwnerId());
		order.setShenqiLogisticsType(999);
		order.setShenqiIdCardRequirement(2);

		return order;
	}

	/**
	 * createOrderItemVo
	 * 
	 * @param productId
	 * @return OrderItemVo
	 */
	public static OrderItemVo createOrderItemVo(String productId,
			String catalogId) {

		OrderItemVo orderItem = new OrderItemVo();

		// BigDecimal price = new BigDecimal(new Random().nextInt(50) + 30);
		BigDecimal price = new BigDecimal(new Random().nextInt(50) + 1301);
		// BigDecimal price = new BigDecimal(new Random().nextInt(50) + 10542);
		BigDecimal freight = new BigDecimal(new Random().nextInt(20) + 10);

		orderItem.setProductPrice(price.subtract(BigDecimal.TEN));
		orderItem.setOriginalPrice(price);

		orderItem.setFreight(freight);
		orderItem.setProductNum(new Random().nextInt(4) + 2);
		// orderItem.setProductNum(1);
		orderItem.setProductId(productId);
		orderItem.setCatalogId(catalogId);
		orderItem.setSalesType(SalesTypeEnum.AlreadyInStock);
		orderItem.setFirstCategoryId(1001);
		orderItem.setSecondCategoryId(1002);
		orderItem.setThirdCategoryId(1003);
		orderItem.setPreSale(false);
		orderItem.setProductRefundChannel(ProductRefundChannelEnum.None);
		orderItem
				.setPictureUrl("http://pic1.ymatou.com/G01/shangou/M00/39/85/rBBlD1k-U5eAMqEfAAIULSyYXWM521_104_78_n_w_o.jpg");
		orderItem.setSku("sku111");
		orderItem.setProperty("属性");
		orderItem.setBrandId(1234);
		orderItem.setProductName("自动化测试商品+" + TestDataManager.getRandomNum(10));
		orderItem.setProductRecordNo("9876");

		return orderItem;
	}

	/**
	 * 根據catalogId 获取关系链
	 * 
	 * @param catalogId
	 * @return
	 */
	public static List<ShenqiProxyChainPo> getProxyChainInfo(String catalogId) {

		List<ShenqiProxyChainPo> shenqiProxyChainPoList = new ArrayList<ShenqiProxyChainPo>();

		YmatouEasyCall queryAgentPriceChainCall = new YmatouEasyCall("",
				"POST", "JSON");
		String orderJson = "{\"catalogIds\":[\"" + catalogId + "\"]}";
		queryAgentPriceChainCall
				.setUrl("http://agentproducts.iapi.ymatou.com/product/queryAgentPriceChain");
		queryAgentPriceChainCall.setData(orderJson);

		try {
			queryAgentPriceChainCall.callService();

			JSONObject data = new JSONObject(
					queryAgentPriceChainCall.getReturnData())
					.optJSONObject("data");

			if (null == data)
				return null;
			else {

				Logger.debug("returndata:"
						+ data.optJSONObject("catalogPriceLinkMap")
								.optJSONArray(catalogId));
				JSONArray proxyChain = data
						.optJSONObject("catalogPriceLinkMap").optJSONArray(
								catalogId);
				
				BigDecimal costPrice = new BigDecimal(data.optJSONObject(
						"costPriceMap").optDouble(catalogId)).setScale(2);

				for (int i = 0; i < proxyChain.length(); i++) {

					JSONObject object = new JSONObject(proxyChain.get(i)
							.toString());
					ShenqiProxyChainPo po = new ShenqiProxyChainPo();

					po.setTitle(object.optString("title"));
					po.setPictureUrl(object.optString("pictureUrl"));
					po.setFromParentPrice(new BigDecimal(object
							.optDouble("fromParentPrice")).setScale(2));
					po.setToChildPrice(new BigDecimal(object
							.optDouble("toChildPrice")).setScale(2));
					po.setIndexInChain(i);
					po.setSellerId(object.optLong("sellerId"));
					po.setCatalogId(catalogId);
					po.setProxyCatalogId(object.optString("catalogId"));
					po.setFromParentPriceType(object
							.optInt("fromParentPriceType"));

					po.setSalePrice(Double.isNaN(object.optDouble("salePrice")) ? null
							: new BigDecimal(object.optDouble("salePrice")));

					if (i == proxyChain.length() - 1) {
						po.setChildSellerId(0L);
					} else {
						po.setChildSellerId(new JSONObject(proxyChain
								.get(i + 1).toString()).optLong("sellerId"));
					}

					String currency = data.getString("currency");
					po.setCurrency(currency);
					po.setCostPrice(costPrice);

					shenqiProxyChainPoList.add(po);
				}
			}

			Logger.debug("ShenqiProxyChainPoList:" + shenqiProxyChainPoList);

		} catch (Exception e) {

			e.printStackTrace();
		}

		return shenqiProxyChainPoList;
	}

	/**
	 * 根據catalogId 获取关系链 分销小店
	 * 
	 * @param catalogId
	 * @return
	 */
	public static List<ShenqiProxyChainPo> getInheritedProxyChainInfo(
			String catalogId, long sellerId) {

		List<ShenqiProxyChainPo> shenqiProxyChainPoList = new ArrayList<ShenqiProxyChainPo>();

		YmatouEasyCall queryAgentPriceChainCall = new YmatouEasyCall("",
				"POST", "JSON");
		String orderJson = "{\"catalogIds\":[\"" + catalogId
				+ "\"], \"userId\":" + sellerId + "}";
		queryAgentPriceChainCall
				.setUrl("http://agentproducts.iapi.ymatou.com/product/queryAgentPriceChain");
		queryAgentPriceChainCall.setData(orderJson);

		try {
			queryAgentPriceChainCall.callService();

			JSONObject data = new JSONObject(
					queryAgentPriceChainCall.getReturnData())
					.optJSONObject("data");

			if (null == data)
				return null;
			else {

				Logger.debug("returndata:"
						+ data.optJSONObject("catalogPriceLinkMap")
								.optJSONArray(catalogId));
				JSONArray proxyChain = data
						.optJSONObject("catalogPriceLinkMap").optJSONArray(
								catalogId);
				BigDecimal costPrice = new BigDecimal(data.optJSONObject(
						"costPriceMap").optDouble(catalogId)).setScale(2);

				for (int i = 0; i < proxyChain.length(); i++) {

					JSONObject object = new JSONObject(proxyChain.get(i)
							.toString());
					ShenqiProxyChainPo po = new ShenqiProxyChainPo();

					po.setTitle(object.optString("title"));
					po.setPictureUrl(object.optString("pictureUrl"));
					po.setFromParentPrice(new BigDecimal(object
							.optDouble("fromParentPrice")).setScale(2));
					po.setToChildPrice(new BigDecimal(object
							.optDouble("toChildPrice")).setScale(2));
					po.setIndexInChain(i);
					po.setSellerId(object.optLong("sellerId"));
					po.setCatalogId(catalogId);
					po.setProxyCatalogId(object.optString("catalogId"));
					po.setFromParentPriceType(object
							.optInt("fromParentPriceType"));
					po.setSalePrice(new BigDecimal(object
							.optString("salePrice")));

					if (i == proxyChain.length() - 1) {
						po.setChildSellerId(0L);
						po.setIsFenxiaoShop(true);
					} else {
						po.setChildSellerId(new JSONObject(proxyChain
								.get(i + 1).toString()).optLong("sellerId"));
					}

					String currency = data.getString("currency");
					po.setCurrency(currency);
					
					po.setCostPrice(costPrice);

					shenqiProxyChainPoList.add(po);
				}
			}

			Logger.debug("ShenqiProxyChainPoList:" + shenqiProxyChainPoList);

		} catch (Exception e) {

			e.printStackTrace();
		}

		return shenqiProxyChainPoList;
	}

	/**
	 * 根據catalogId, sellerid 获取sellerid对应的规格价格
	 * 
	 * @param catalogId
	 * @param sellerId
	 * @return
	 */
	public static ShenqiProxyChainPo getProxyChainInfo(String catalogId,
			long sellerId) {

		ShenqiProxyChainPo po = new ShenqiProxyChainPo();

		YmatouEasyCall queryAgentPriceChainCall = new YmatouEasyCall("",
				"POST", "JSON");
		String orderJson = "{\"catalogIds\":[\"" + catalogId
				+ "\"], \"userId\":" + sellerId + "}";
		queryAgentPriceChainCall
				.setUrl("http://agentproducts.iapi.ymatou.com/product/queryAgentPriceChain");
		queryAgentPriceChainCall.setData(orderJson);

		try {
			queryAgentPriceChainCall.callService();

			JSONObject data = new JSONObject(
					queryAgentPriceChainCall.getReturnData())
					.optJSONObject("data");

			if (null == data)
				return null;
			else {

				Logger.debug("returndata:"
						+ data.optJSONObject("catalogPriceLinkMap")
								.optJSONArray(catalogId));
				JSONArray proxyChain = data
						.optJSONObject("catalogPriceLinkMap").optJSONArray(
								catalogId);

				for (int i = 0; i < proxyChain.length(); i++) {

					JSONObject object = new JSONObject(proxyChain.get(i)
							.toString());

					if (object.optLong("sellerId") == sellerId) {

						po = new ShenqiProxyChainPo();

						po.setTitle(object.optString("title"));
						po.setPictureUrl(object.optString("pictureUrl"));
						po.setFromParentPrice(new BigDecimal(object
								.optDouble("fromParentPrice")).setScale(2));
						po.setToChildPrice(new BigDecimal(object
								.optDouble("toChildPrice")).setScale(2));
						po.setIndexInChain(i);
						po.setSellerId(object.optLong("sellerId"));
						po.setCatalogId(catalogId);
						po.setFromParentPriceType(object
								.optInt("fromParentPriceType"));

						if (i == proxyChain.length() - 1) {
							po.setChildSellerId(0L);
						} else {
							po.setChildSellerId(new JSONObject(proxyChain.get(
									i + 1).toString()).optLong("sellerId"));
						}
					}
				}

				String currency = data.getString("currency");
				po.setCurrency(currency);
			}

			Logger.debug("shenqiProxyChainPo:" + po);

		} catch (Exception e) {

			e.printStackTrace();
		}

		return po;
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean)
			throws Exception {

		return placeOrder(productBean, BigDecimal.ZERO);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithEntryInfo(
			AgentProductBean productBean) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO, 20238699,
						productBean, (int) autotest_goodsOwnerId);

		placeOrderReq.setEntryIdType(1);
		placeOrderReq.setEntryIdNo(TestDataManager.randomStr(8));
		placeOrderReq.setEntryTime(YMTDateUtil.getBeforeOrNextDate(
				YMTDateUtil.getDate(), 1));
		placeOrderReq.setEntryPort("entryPPPPP");
		placeOrderReq.setTransportation("autotest_flight");

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithPayChannelType(
			AgentProductBean productBean, Long goodsOwnerId,
			Integer payChannelType) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setDiscount(BigDecimal.ZERO);
		placeOrderReq.setPayChannelType(payChannelType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithUserId(
			AgentProductBean productBean, Long userId) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, productBean.getGoodsOwnerId(), false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp placeOrderWithSalesman(
			AgentProductBean productBean, Long salesman) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(salesman, BigDecimal.ZERO, userId,
						productBean, autotest_goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp placeOrderWithUserIdAndSaleman(
			AgentProductBean productBean, Long userId, Long salesman)
			throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(Utils.zeroIfNull(salesman), BigDecimal.ZERO, userId,
						productBean, autotest_goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithUserIdAndSalemanAndGoodsOwnerId(
			AgentProductBean productBean, Long userId, Long salesman, Long goodsOwnerId)
			throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(Utils.zeroIfNull(salesman), BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithUserIdAndSalemanAndGoodsOwnerIdAndIntegral(
			AgentProductBean productBean, Long userId, Long salesman, Long goodsOwnerId, Long integral)
			throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(Utils.zeroIfNull(salesman), BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));
		placeOrderReq.setIntegral(integral);
		placeOrderReq.setShenqiProxyBuyOrder(true);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithMultiProduct(
			AgentProductBean productBean, Long userId) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0L, BigDecimal.TEN, userId,
						productBean, autotest_goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		// 定义买手下的优惠商品信息list
		List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

		SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

		sellerPromotion1.setAmountCondition(new BigDecimal(100));
		sellerPromotion1.setId(123456789);
		sellerPromotion1.setName("自动化商家优惠活动");

		sellerPromotion1.setPromotionValue(new BigDecimal(12));
		sellerPromotion1.setQtyCondition(4);

		sellerPromotion1.setReducedAmount(new BigDecimal(15));
		sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

		sellerPromotion1.setApportions(Arrays.asList(new CatalogApportionVo(
				orderItemVo1.getCatalogId(), orderItemVo1.getProductNum()),
				new CatalogApportionVo(orderItemVo2.getCatalogId(),
						orderItemVo2.getProductNum())));

		sellerPromotionList.add(sellerPromotion1);

		placeOrderReq.getOrderGroups().get(0)
				.setSellerPromotionApportions(sellerPromotionList);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithAgentProductList(
			List<AgentProductBean> productBeanList, Long userId) throws Exception {

		PlaceOrderReq placeOrderReq = null;
		
		for (int i = 0; i < productBeanList.size(); i++) {
			
			AgentProductBean productBean = productBeanList.get(i);
			
			if (i == 0) {
				
				placeOrderReq = TradingForDGSQCallService
						.buildDGSQStandPlaceOrderReq(0L, BigDecimal.TEN, userId,
								productBean, autotest_goodsOwnerId, false);
				
				placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
				placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
						.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
			} else {
				
				OrderItemVo orderItemVo = TradingForDGSQCallService
						.createOrderItemVo(productBean.getProductId(), productBean
								.getCatalogList().get(0));

				placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
						.getOrderItems().add(orderItemVo);
			}	
		}
		
		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithAgentProductListAndGoodsOwnerId(
			List<AgentProductBean> productBeanList, Long userId, Long goodsOwnerId) throws Exception {

		PlaceOrderReq placeOrderReq = null;
		
		for (int i = 0; i < productBeanList.size(); i++) {
			
			AgentProductBean productBean = productBeanList.get(i);
			
			if (i == 0) {
				
				placeOrderReq = TradingForDGSQCallService
						.buildDGSQStandPlaceOrderReq(0L, BigDecimal.TEN, userId,
								productBean, goodsOwnerId, false);
				
				placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
				placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
						.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
			} else {
				
				OrderItemVo orderItemVo = TradingForDGSQCallService
						.createOrderItemVo(productBean.getProductId(), productBean
								.getCatalogList().get(0));

				placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
						.getOrderItems().add(orderItemVo);
			}	
		}
		
		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithUserIdAndCurrency(
			AgentProductBean productBean, Long userId, String currency)
			throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0L, BigDecimal.ZERO, userId,
						productBean, autotest_goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithUserIdAndGoodsOwnerIdAndCurrency(
			AgentProductBean productBean, Long userId, Long goodsOwnerId,
			String currency) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithUserIdAndGoodsOwnerIdAndCurrencyAndIntegral(
			AgentProductBean productBean, Long userId, Long goodsOwnerId,
			String currency, Long integral) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		placeOrderReq.setCurrency(currency);
		placeOrderReq.setIntegral(integral);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个神器代理订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			Boolean shenqiProxyOrder) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		placeOrderReq.setShenqiProxyBuyOrder(true);
		placeOrderReq.setShenqiBuyOrderCsId(1235678L);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 下单带有purchaserIdcardId
	 * 由于ShenqiLogisticsType为4，sit无法自动接单
	 * @return
	 */
	public static TradingServiceResp placeOrderWithPurchaserIdcardId(
			AgentProductBean productBean, Long purchaserIdcardId) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setPurchaserIdcardId(purchaserIdcardId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setShenqiIdCardRequirement(1);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setShenqiLogisticsType(4);
		placeOrderReq.setRecvMobile("13671492546");

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithBlackList(
			AgentProductBean productBean, Long purchaserIdcardId, Long goodsOwnerId) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setPurchaserIdcardId(purchaserIdcardId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setShenqiIdCardRequirement(1);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setShenqiLogisticsType(4);
		placeOrderReq.setRecvMobile("13671492546");

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 下单带有WarehouseId
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrderWithWarehouseId(
			AgentProductBean productBean, Integer purchaserIdcardId) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setWarehouseId(purchaserIdcardId);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			Integer customSettlementCurrencyType, Long goodsOwnerId,
			String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(BigDecimal.ZERO);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setCurrency(currency);
		placeOrderReq
				.setCustomSettlementCurrencyType(customSettlementCurrencyType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			Integer customSettlementCurrencyType, Integer payChannelType,
			Long goodsOwnerId, String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setPayChannelType(payChannelType);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(BigDecimal.ZERO);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setCurrency(currency);
		placeOrderReq
				.setCustomSettlementCurrencyType(customSettlementCurrencyType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static PlaceOrderReq placeOrderOver50000(
			AgentProductBean productBean, Integer payChannelType,
			Long goodsOwnerId, String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setPayChannelType(payChannelType);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		if (currency.equalsIgnoreCase("USD")) {

			orderItemVo.setProdTaxRate(BigDecimal.ZERO);
			orderItemVo.setProductPrice(new BigDecimal("10000"));
			orderItemVo.setProductNum(1);
		} else {

			orderItemVo.setProdTaxRate(BigDecimal.ZERO);
			orderItemVo.setProductPrice(new BigDecimal("10001"));
			orderItemVo.setProductNum(5);
		}

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setCurrency(currency);

		return placeOrderReq;
	}

	/**
	 * 下单支持线下支付，且触发风控规则
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderTriggerRiskControlWithSupportOfflinePay(
			AgentProductBean productBean) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO, 20238699,
						productBean, (int) autotest_goodsOwnerId);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		orderItemVo.setProductPrice(new BigDecimal("20000"));
		orderItemVo.setProductNum(3);

		orderItemVo.setFreight(BigDecimal.ZERO);

		placeOrderReq.setSupportOfflinePay(true);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp callPlaceOrderService(
			PlaceOrderReq placeOrderReq) {

		PlaceOrderCall placeorderCall = new PlaceOrderCall();

		TradingServiceResp orderResp = new TradingServiceResp();

		placeorderCall.setData(false, placeOrderReq);

		try {

			if (placeOrderReq.getMainOrderId() % 10000 != placeOrderReq
					.getUserId() % 10000) {

				// 设置主单号
				placeOrderReq.setMainOrderId(genMainOrderId(placeOrderReq
						.getUserId()));
			}

			placeorderCall.callService();

			// 如果下单失败，则重试3次，如果依然失败，则抛出exception
			int n = 0;
			retryPlaceOrder(placeorderCall, n);

			long userId = placeOrderReq.getUserId();

			orderResp.setUserId(userId);

			List<Long> orderIds = placeorderCall.getPlaceOrderResp()
					.getOrderIds();

			List<Order> orderList = new ArrayList<Order>();

			for (int i = 0; i < orderIds.size(); i++) {

				Order order = new Order();

				long orderId = orderIds.get(i);

				OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

				OrderPo orderPo = orderShardingWapper
						.selectOrderbyOrderId(orderId);

				List<OrderDetailPo> orderDetailPoList = orderShardingWapper
						.selectOrderDetailbyOrderId(orderId);

				order.setOrderPo(orderPo);
				order.setOrderDetailPoList(orderDetailPoList);

				orderList.add(order);

			}

			if (placeOrderReq.getBizSource() != null) {

				orderResp.setBizId(placeOrderReq.getBizSource().getBizId());
			}

			orderResp.setOrderList(orderList);

			orderResp.setMainOrderId(placeOrderReq.getMainOrderId());

		} catch (Exception e) {

			e.printStackTrace();

		}

		return orderResp;
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			long goodsOwnerId) throws Exception {

		return placeOrder(productBean, BigDecimal.ZERO, goodsOwnerId, null);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			BigDecimal discount) throws Exception {

		return placeOrder(productBean, discount, autotest_goodsOwnerId, null);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			BigDecimal discount, long goodsOwnerId, String currency)
			throws Exception {

		return placeOrder(productBean, discount, goodsOwnerId, currency, null,
				false);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			BigDecimal discount, long goodsOwnerId, String currency,
			Boolean supportOfflinePay) throws Exception {

		return placeOrder(productBean, discount, goodsOwnerId, currency, null,
				supportOfflinePay);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			BigDecimal discount, long goodsOwnerId, String currency,
			BigDecimal taxRate) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(taxRate);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setDiscount(discount);
		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp placeOrderWithSelfPickup(
			AgentProductBean productBean, Long goodsOwnerId,
			Boolean pickupInStores) {

		return placeOrderWithSelfPickup(productBean, goodsOwnerId,
				pickupInStores, null);
	}

	/**
	 * 1个买手,1个商品,生成自提订单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrderWithSelfPickup(
			AgentProductBean productBean, Long goodsOwnerId,
			Boolean pickupInStores, Integer vStockCount) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		// 实际库存10 + 虚拟库存2
		orderItemVo.setProductNum(10 + (vStockCount == null ? 0 : vStockCount));

		placeOrderReq.setPickupInStores(pickupInStores);
		PickInStoreVo pickInStoreVo = new PickInStoreVo();

		pickInStoreVo.setPickupStoreId((long) TestDataManager
				.getRandomIntNum(6));
		pickInStoreVo.setPickupType(0);
		pickInStoreVo.setPickupUserName(TestDataManager.getChineseName());
		pickInStoreVo.setPickupUserPhone(TestDataManager.getPhoneNum());
		pickInStoreVo.setUserReserveTimeSpanStart(YMTDateUtil
				.getBeforeOrNextDate(0));
		pickInStoreVo.setUserReserveTimeSpanEnd(YMTDateUtil
				.getBeforeOrNextDate(10));

		placeOrderReq.setPickInStoreVo(pickInStoreVo);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder(AgentProductBean productBean,
			BigDecimal discount, long goodsOwnerId, String currency,
			BigDecimal taxRate, Boolean supportOfflinePay) throws Exception {

//		int userId = new OrderCallService().createNewUser();
		int userId = 20238699;

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(taxRate);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setDiscount(discount);
		placeOrderReq.setCurrency(currency);
		
		placeOrderReq.setSupportOfflinePay(supportOfflinePay);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithAllPromotionAndCurrency(
			AgentProductBean productBean, BigDecimal discount,
			long goodsOwnerId, String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, true);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));

		orderItemVo1.setFullReductionFreeFreight(true);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		orderItemVo2.setProdTaxRate(new BigDecimal("0.47"));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		// 定义买手下的优惠商品信息list
		List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

		SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

		sellerPromotion1.setAmountCondition(new BigDecimal(100));
		sellerPromotion1.setId(123456789);
		sellerPromotion1.setName("自动化商家优惠活动");

		sellerPromotion1.setPromotionValue(new BigDecimal(12));
		sellerPromotion1.setQtyCondition(4);

		sellerPromotion1.setReducedAmount(new BigDecimal("5.00"));
		sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

		sellerPromotion1.setApportions(Arrays.asList(
				new CatalogApportionVo(productBean.getCatalogList().get(0),
						orderItemVo1.getProductNum()),
				new CatalogApportionVo(orderItemVo2.getCatalogId(),
						orderItemVo2.getProductNum())));

		sellerPromotionList.add(sellerPromotion1);

		placeOrderReq.getOrderGroups().get(0)
				.setSellerPromotionApportions(sellerPromotionList);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setRegionDiscountRatio(new BigDecimal("9.50"));
		placeOrderReq.setDiscount(discount);

		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithAllPromotion(
			AgentProductBean productBean, BigDecimal discount, long goodsOwnerId)
			throws Exception {

		return placeOrderWithAllPromotionAndCurrency(productBean, discount,
				goodsOwnerId, null);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderNegativeProfit(
			AgentProductBean productBean, BigDecimal discount,
			long goodsOwnerId, String currency, BigDecimal taxRate,
			Boolean supportOfflinePay) throws Exception {

		return placeOrderNegativeProfit(productBean, discount, goodsOwnerId,
				currency, taxRate, supportOfflinePay, null);
	}

	/**
	 * 1个买手,多个个商品,生成负利润订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderNegativeProfit(
			AgentProductBean productBean, BigDecimal discount,
			long goodsOwnerId, String currency, BigDecimal taxRate,
			Boolean supportOfflinePay, Integer payChannelType) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		orderItemVo2.setProdTaxRate(new BigDecimal("0.47"));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		BigDecimal discount1 = orderItemVo1.getProductPrice().multiply(
				new BigDecimal(orderItemVo1.getProductNum()));

		BigDecimal discount2 = orderItemVo2.getProductPrice().multiply(
				new BigDecimal(orderItemVo2.getProductNum()));

		// 定义买手下的优惠商品信息list
		List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

		SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

		sellerPromotion1.setAmountCondition(new BigDecimal(100));
		sellerPromotion1.setId(123456789);
		sellerPromotion1.setName("自动化商家优惠活动");

		sellerPromotion1.setPromotionValue(new BigDecimal(12));
		sellerPromotion1.setQtyCondition(4);

		sellerPromotion1.setReducedAmount(discount1.add(discount2));
		sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

		sellerPromotion1.setApportions(Arrays.asList(
				new CatalogApportionVo(productBean.getCatalogList().get(0),
						orderItemVo1.getProductNum()),
				new CatalogApportionVo(orderItemVo2.getCatalogId(),
						orderItemVo2.getProductNum())));

		sellerPromotionList.add(sellerPromotion1);

		placeOrderReq.getOrderGroups().get(0)
				.setSellerPromotionApportions(sellerPromotionList);
		placeOrderReq.setCurrency(currency);

		if (null != payChannelType)
			placeOrderReq.setPayChannelType(payChannelType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderNegativeProfitWithUserId(
			AgentProductBean productBean, BigDecimal discount,
			long goodsOwnerId, String currency, Long userId,
			Boolean isDistributorAmountZero) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0L, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		orderItemVo2.setProdTaxRate(new BigDecimal("0.47"));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		BigDecimal discount1 = BigDecimal.ZERO;
		BigDecimal discount2 = BigDecimal.ZERO;

		if (!isDistributorAmountZero) {

			BigDecimal orderItemAgentPrice1 = new BigDecimal(productBean
					.getAgentCatalogPriceList().get(0).getAgentPrice());
			BigDecimal orderItemAgentPrice2 = new BigDecimal(productBean
					.getAgentCatalogPriceList().get(1).getAgentPrice());

			discount1 = (orderItemVo1.getProductPrice().subtract(
					orderItemAgentPrice1).subtract(BigDecimal.TEN))
					.multiply(new BigDecimal(orderItemVo1.getProductNum()));

			discount2 = (orderItemVo2.getProductPrice().subtract(
					orderItemAgentPrice2).subtract(BigDecimal.TEN))
					.multiply(new BigDecimal(orderItemVo2.getProductNum()));

		} else {

			discount1 = orderItemVo1.getProductPrice().multiply(
					new BigDecimal(orderItemVo1.getProductNum()));

			discount2 = orderItemVo2.getProductPrice().multiply(
					new BigDecimal(orderItemVo2.getProductNum()));
		}

		// 定义买手下的优惠商品信息list
		List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

		SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

		sellerPromotion1.setAmountCondition(new BigDecimal(100));
		sellerPromotion1.setId(123456789);
		sellerPromotion1.setName("自动化商家优惠活动");

		sellerPromotion1.setPromotionValue(new BigDecimal(12));
		sellerPromotion1.setQtyCondition(4);

		sellerPromotion1.setReducedAmount(discount1.add(discount2));
		sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

		sellerPromotion1.setApportions(Arrays.asList(
				new CatalogApportionVo(productBean.getCatalogList().get(0),
						orderItemVo1.getProductNum()),
				new CatalogApportionVo(orderItemVo2.getCatalogId(),
						orderItemVo2.getProductNum())));

		sellerPromotionList.add(sellerPromotion1);

		placeOrderReq.getOrderGroups().get(0)
				.setSellerPromotionApportions(sellerPromotionList);
		placeOrderReq.setCurrency(currency);

		placeOrderReq.setPayChannelType(1);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个个商品,生成0利润订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderZeroProfit(
			AgentProductBean productBean, long goodsOwnerId, String currency,
			Integer payChannelType) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		orderItemVo1.setProductPrice(new BigDecimal(productBean
				.getAgentCatalogPriceList()
				.stream()
				.filter(catalogPrice -> catalogPrice.getCatalogId()
						.equalsIgnoreCase(orderItemVo1.getCatalogId()))
				.collect(Collectors.toList()).get(0).getAgentPrice())
				.add(BigDecimal.TEN));

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		orderItemVo2.setProductPrice(new BigDecimal(productBean
				.getAgentCatalogPriceList()
				.stream()
				.filter(catalogPrice -> catalogPrice.getCatalogId()
						.equalsIgnoreCase(orderItemVo2.getCatalogId()))
				.collect(Collectors.toList()).get(0).getAgentPrice()));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		BigDecimal discount = new BigDecimal(orderItemVo1.getProductNum())
				.multiply(BigDecimal.TEN);

		placeOrderReq.setCurrency(currency);
		placeOrderReq.setDiscount(discount.negate());

		if (null != payChannelType)
			placeOrderReq.setPayChannelType(payChannelType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成带有订单别名单个神器代理订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithOrderAlias(
			AgentProductBean productBean, String orderAlias) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		placeOrderReq.setShenqiProxyBuyOrder(true);
		placeOrderReq.setShenqiBuyOrderCsId(1235678L);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setOrderAlias(orderAlias);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,1个商品,生成带有订单别名单个神器代理订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithVStockCount(
			AgentProductBean productBean, Integer vStockCount) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234L, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		placeOrderReq.setShenqiProxyBuyOrder(true);
		placeOrderReq.setShenqiBuyOrderCsId(1235678L);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProductNum(10 + vStockCount);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,生成1个订单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrderWithMultiProsInOneOrder(AgentProductBean productBean) {

		return placeOrderWithMultiProsInOneOrder(productBean, null);
	}

	public static TradingServiceResp placeOrderWithMultiProsInOneOrderWithIntegral(AgentProductBean productBean,
			Long integral) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, productBean.getGoodsOwnerId());

		OrderItemVo orderItemVo = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setFreight(BigDecimal.ZERO);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo);
		
		placeOrderReq.setShenqiProxyBuyOrder(true);
		placeOrderReq.setIntegral(integral);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 1个买手,多个商品,生成1个订单,包含税费
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrderWithMultiProsInOneOrder(AgentProductBean productBean,
			BigDecimal taxRate) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(taxRate);

		OrderItemVo orderItemVo = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));

		orderItemVo.setProdTaxRate(taxRate);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithUserIdAndMultiProsInOneOrder(AgentProductBean productBean,
			Long userId) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId);

		OrderItemVo orderItemVo = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));

		placeOrderReq.setUserId(userId);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 直销商外币下单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrder1(AgentProductBean productBean,
			long sellerId, String currency) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, sellerId);
		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 直销商下单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrder1(AgentProductBean productBean,
			long sellerId) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, sellerId, true, false);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 直销商下单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrder1(AgentProductBean productBean,
			long sellerId, Boolean supportOfflinePay) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, sellerId, true, supportOfflinePay);

		placeOrderReq.getOrderGroups().get(0)
				.setServiceRate(new BigDecimal("6.00"));
		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		orderItemVo.setProdTaxRate(new BigDecimal("0.17"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 直销商下单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrder1(AgentProductBean productBean,
			long goodOwnerId, int vStockCount) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodOwnerId, false, false);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		// 实际库存10 + 虚拟库存2
		orderItemVo.setProductNum(10 + vStockCount);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,生成2个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder2(BigDecimal discount,
			AgentProductBean productBean, Integer payChannelType)
			throws Exception {

		return placeOrder2(discount, productBean, null, payChannelType);
	}

	/**
	 * 1个买手,多个商品,生成2个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder2(BigDecimal discount,
			AgentProductBean productBean, String currency,
			Integer payChannelType) throws Exception {

		return placeOrder2(discount, productBean, currency, null,
				autotest_goodsOwnerId, payChannelType);
	}

	/**
	 * 1个买手,多个商品,生成2个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder2(AgentProductBean productBean,
			Long goodsOwnerId, String currency, Boolean supportOfflinePay)
			throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		OrderVo orderVo = createOrderVo(Lists.newArrayList(productBean));

		orderVo.getOrderItems().get(0).setProductId(productBean.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(productBean.getCatalogList().get(1));

		orderVo.getOrderItems().get(0).setProductNum(1);

		orderVo.setGoodsOwnerId(goodsOwnerId);
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		placeOrderReq.setCurrency(currency);

		placeOrderReq.setSupportOfflinePay(supportOfflinePay);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,生成2个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder2(BigDecimal discount,
			AgentProductBean productBean, String currency, BigDecimal taxRate,
			Long goodsOwnerId, Integer payChannelType) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		// placeOrderReq.setUserId(25380404);

		// 设置taxRate
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(taxRate);

		// placeOrderReq.getOrderGroups().get(0).getOrders().get(0).getOrderItems().get(0).setProductNum(1);

		OrderVo orderVo = createOrderVo(Lists.newArrayList(productBean));
		//
		orderVo.getOrderItems().get(0).setProductId(productBean.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(productBean.getCatalogList().get(1));

		orderVo.getOrderItems().get(0).setProductNum(1);
		//
		orderVo.setGoodsOwnerId(goodsOwnerId);
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		placeOrderReq.setDiscount(discount);
		placeOrderReq.setCurrency(currency);

		placeOrderReq.setPayChannelType(payChannelType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrder2WithUserId(BigDecimal discount,
			AgentProductBean productBean, String currency, BigDecimal taxRate,
			Long goodsOwnerId, Integer payChannelType, Long userId) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId);

		// 设置taxRate
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(taxRate);

		// placeOrderReq.getOrderGroups().get(0).getOrders().get(0).getOrderItems().get(0).setProductNum(1);

		OrderVo orderVo = createOrderVo(Lists.newArrayList(productBean));
		//
		orderVo.getOrderItems().get(0).setProductId(productBean.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(productBean.getCatalogList().get(1));

		orderVo.getOrderItems().get(0).setProductNum(1);
		//
		orderVo.setGoodsOwnerId(goodsOwnerId);
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		placeOrderReq.setDiscount(discount);
		placeOrderReq.setCurrency(currency);

		placeOrderReq.setPayChannelType(payChannelType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,生成2个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder2(BigDecimal discount,
			AgentProductBean productBean, String currency, BigDecimal taxRate,
			Long goodsOwnerId, Integer customSettlementCurrencyType,
			Integer payChannelType) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		// placeOrderReq.setUserId(25380404);

		// 设置taxRate
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(taxRate);

		// placeOrderReq.getOrderGroups().get(0).getOrders().get(0).getOrderItems().get(0).setProductNum(1);

		OrderVo orderVo = createOrderVo(Lists.newArrayList(productBean));
		//
		orderVo.getOrderItems().get(0).setProductId(productBean.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(productBean.getCatalogList().get(1));

		orderVo.getOrderItems().get(0).setProductNum(1);
		//
		orderVo.setGoodsOwnerId(goodsOwnerId);
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		placeOrderReq.setDiscount(discount);
		placeOrderReq.setCurrency(currency);

		placeOrderReq
				.setCustomSettlementCurrencyType(customSettlementCurrencyType);
		placeOrderReq.setPayChannelType(payChannelType);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,包含虚拟库存,生成2个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeVStockOrder2(
			AgentProductBean productBean) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO, 20238699,
						productBean, (int) autotest_goodsOwnerId);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		// 实际库存12 + 虚拟库存2
		orderItemVo.setProductNum(12);
		orderItemVo.setVirtualProductNum(2);

		// 第二个订单
		OrderVo orderVo = TradingForDGSQCallService.createOrderVo(Arrays
				.asList(productBean));

		orderVo.getOrderItems().get(0).setProductNum(1);
		orderVo.getOrderItems().get(0).setVirtualProductNum(1);

		orderVo.setGoodsOwnerId(autotest_goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,包含虚拟库存,生成1个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeVStockOrder3(
			AgentProductBean productBean) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId, false, false);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		// 虚拟库存1
		orderItemVo.setProductNum(12);

		AgentProductBean productBean1 = new AgentProductBean();

		String productId1 = DGSQBaseService.createAgentProduct(
				(int) autotest_goodsOwnerId, "autotest_goodsOwnerId", true,
				"CNY", true);

		productBean1.setSellerId(autotest_goodsOwnerId);
		productBean1.setSellerLoginId(new DGUserWapper()
				.selectDGUserInfo((int) autotest_goodsOwnerId).get(0)
				.getLoginId());
		productBean1.setProductId(productId1);
		productBean1.setRootProductId(productId1);
		productBean1.setCatalogList(DGSQBaseService
				.getCatalogIdList(productId1));
		productBean1.setRootCatalogList(DGSQBaseService
				.getCatalogIdList(productId1));
		productBean1.setGoodsOwnerId(autotest_goodsOwnerId);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService.createOrderItemVo(
				productId1, productBean1.getCatalogList().get(0));
		orderItemVo2.setProductNum(12);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 1个买手,多个商品,一个虚拟库存，一个真实库存,生成1个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeVStockOrder4(
			AgentProductBean productBean) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId, false, false);

		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		// 虚拟库存1
		orderItemVo.setProductNum(12);

		AgentProductBean productBean1 = new AgentProductBean();

		String productId1 = DGSQBaseService.createAgentProduct(
				(int) autotest_goodsOwnerId, "autotest_goodsOwnerId", true,
				"CNY", true);

		productBean1.setSellerId(autotest_goodsOwnerId);
		productBean1.setSellerLoginId(new DGUserWapper()
				.selectDGUserInfo((int) autotest_goodsOwnerId).get(0)
				.getLoginId());
		productBean1.setProductId(productId1);
		productBean1.setRootProductId(productId1);
		productBean1.setCatalogList(DGSQBaseService
				.getCatalogIdList(productId1));
		productBean1.setRootCatalogList(DGSQBaseService
				.getCatalogIdList(productId1));
		productBean1.setGoodsOwnerId(autotest_goodsOwnerId);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService.createOrderItemVo(
				productId1, productBean1.getCatalogList().get(0));
		orderItemVo2.setProductNum(2);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 继承代理订单
	 * 
	 * @param productBean
	 * @param goodsOwnerId
	 * @param salesman
	 * @param isPromotion
	 * @return
	 */
	public static TradingServiceResp placeInheritedOrder(
			AgentProductBean productBean, long goodsOwnerId, long salesman,
			boolean isPromotion) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(salesman, BigDecimal.ZERO,
						20238699, productBean, goodsOwnerId, isPromotion, false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));
		orderItemVo1.setProductPrice(new BigDecimal("100.00"));
		orderItemVo1.setProductNum(1);

		if (isPromotion) {

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays
					.asList(new CatalogApportionVo(productBean.getCatalogList()
							.get(0), orderItemVo1.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			placeOrderReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);
		}

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 继承代理多商品订单
	 * 
	 * @param productBean
	 * @param goodsOwnerId
	 * @param salesman
	 * @param isPromotion
	 * @return
	 */
	public static TradingServiceResp placeInheritedOrderMultiProduct(
			AgentProductBean productBean, long goodsOwnerId, long salesman,
			boolean isPromotion) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(salesman, BigDecimal.ZERO,
						20238699, productBean, goodsOwnerId, isPromotion, false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));
		orderItemVo1.setProductPrice(new BigDecimal("165.00"));
		orderItemVo1.setProductNum(1);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		orderItemVo2.setProdTaxRate(new BigDecimal("0.47"));
		orderItemVo2.setProductPrice(new BigDecimal("168.00"));
		orderItemVo2.setProductNum(1);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		if (isPromotion) {

			// 定义买手下的优惠商品信息list
			List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

			SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

			sellerPromotion1.setAmountCondition(new BigDecimal(100));
			sellerPromotion1.setId(123456789);
			sellerPromotion1.setName("自动化商家优惠活动");

			sellerPromotion1.setPromotionValue(new BigDecimal(12));
			sellerPromotion1.setQtyCondition(4);

			sellerPromotion1.setReducedAmount(new BigDecimal(15));
			sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

			sellerPromotion1.setApportions(Arrays.asList(
					new CatalogApportionVo(productBean.getCatalogList().get(0),
							orderItemVo1.getProductNum()),
					new CatalogApportionVo(orderItemVo2.getCatalogId(),
							orderItemVo2.getProductNum())));

			sellerPromotionList.add(sellerPromotion1);

			placeOrderReq.getOrderGroups().get(0)
					.setSellerPromotionApportions(sellerPromotionList);
		}

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp placeOrderWithSuppliers(Long supplier_1,
			int supplier_count_1, Long supplier_2, int supplier_count_2)
			throws Exception {

		return placeOrderWithSuppliers(supplier_1, supplier_count_1,
				supplier_2, supplier_count_2, null);
	}

	/**
	 * 单买手,多商品，多货头,生成多个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithSuppliersAndDistributor(
			Long supplier_1, int supplier_count_1, Long supplier_2,
			int supplier_count_2, Integer payChannelType) throws Exception {

		Long userId = (long) new OrderCallService().createNewUser();

		// 美元货头
		AgentProductBean supplierProductBean_1 = DGSQBuildProxyChainCallService
				.createGoodsOwnerProduct(supplier_1, "CNY", false);

		AgentProductBean productBean_1 = DGSQBuildProxyChainCallService
				.createChannel(supplierProductBean_1.getSellerId(),
						supplierProductBean_1.getProductId(), "HKG");

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						productBean_1, autotest_goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProductNum(supplier_count_1);

		AgentProductBean supplierProductBean_2 = DGSQBuildProxyChainCallService
				.createGoodsOwnerProduct(supplier_2, "CNY", false);

		AgentProductBean productBean_2 = DGSQBuildProxyChainCallService
				.createChannel(supplierProductBean_2.getSellerId(),
						supplierProductBean_2.getProductId(),
						productBean_1.getCurrency(),
						productBean_1.getSellerId());

		Long merchantId = productBean_1.getSellerId();

		List<Long> distributorList = SqDistributorService
				.buildSqDistributorRelation(merchantId, 0, 3, 0);

		SqDistributorService.setDistributorConfig(merchantId, 2, false);
		SqDistributorService.bindDistributorConsumerRelation(userId,
				merchantId, distributorList.get(2));

		OrderVo orderVo = TradingForDGSQCallService.createOrderVo(Lists
				.newArrayList(productBean_2));

		orderVo.getOrderItems().get(0)
				.setProductId(productBean_2.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(productBean_2.getCatalogList().get(0));
		orderVo.getOrderItems().get(0).setProductNum(supplier_count_2);

		orderVo.setGoodsOwnerId(supplierProductBean_2.getSellerId());
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		if (null != payChannelType)
			placeOrderReq.setPayChannelType(payChannelType);
		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 单买手,多商品，多货头,生成多个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithSuppliers(Long supplier_1,
			int supplier_count_1, Long supplier_2, int supplier_count_2,
			Integer payChannelType) throws Exception {

		int userId = new OrderCallService().createNewUser();

		// 美元货头
		AgentProductBean supplierProductBean_1 = DGSQBuildProxyChainCallService
				.createGoodsOwnerProduct(supplier_1, "CNY", false);

		AgentProductBean productBean_1 = DGSQBuildProxyChainCallService
				.createChannel(supplierProductBean_1.getSellerId(),
						supplierProductBean_1.getProductId(), "HKG");

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						productBean_1, autotest_goodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProductNum(supplier_count_1);

		AgentProductBean supplierProductBean_2 = DGSQBuildProxyChainCallService
				.createGoodsOwnerProduct(supplier_2, "CNY", false);

		AgentProductBean productBean_2 = DGSQBuildProxyChainCallService
				.createChannel(supplierProductBean_2.getSellerId(),
						supplierProductBean_2.getProductId(),
						productBean_1.getCurrency(),
						productBean_1.getSellerId());

		OrderVo orderVo = TradingForDGSQCallService.createOrderVo(Lists
				.newArrayList(productBean_2));

		orderVo.getOrderItems().get(0)
				.setProductId(productBean_2.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(productBean_2.getCatalogList().get(0));
		orderVo.getOrderItems().get(0).setProductNum(supplier_count_2);

		orderVo.setGoodsOwnerId(supplierProductBean_2.getSellerId());
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		if (null != payChannelType)
			placeOrderReq.setPayChannelType(payChannelType);
		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 单买手,多商品，多货头,生成多个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithTwoSuppliers(
			AgentProductBean supplier_1, int supplier_count_1,
			AgentProductBean supplier_2, int supplier_count_2) throws Exception {

		return placeOrderWithTwoSuppliers(supplier_1, supplier_count_1,
				supplier_2, supplier_count_2, null, null);
	}

	/**
	 * 单买手,多商品，多货头,生成多个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithTwoSuppliers(
			AgentProductBean supplier_1, int supplier_count_1,
			AgentProductBean supplier_2, int supplier_count_2, String currency,
			Integer payChannelType) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						supplier_1, supplier_1.getGoodsOwnerId());

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProductNum(supplier_count_1);

		OrderVo orderVo = TradingForDGSQCallService.createOrderVo(Lists
				.newArrayList(supplier_2));

		orderVo.getOrderItems().get(0).setProductId(supplier_2.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(supplier_2.getCatalogList().get(0));
		orderVo.getOrderItems().get(0).setProductNum(supplier_count_2);

		orderVo.setGoodsOwnerId(supplier_2.getGoodsOwnerId());
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		placeOrderReq.setCurrency(currency);

		if (null != payChannelType)
			placeOrderReq.setPayChannelType(payChannelType);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithTwoSuppliersAndUserId(
			AgentProductBean supplier_1, int supplier_count_1,
			AgentProductBean supplier_2, int supplier_count_2, String currency,
			Integer payChannelType, Long userId) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, userId,
						supplier_1, supplier_1.getGoodsOwnerId());

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProductNum(supplier_count_1);

		OrderVo orderVo = TradingForDGSQCallService.createOrderVo(Lists
				.newArrayList(supplier_2));

		orderVo.getOrderItems().get(0).setProductId(supplier_2.getProductId());
		orderVo.getOrderItems().get(0)
				.setCatalogId(supplier_2.getCatalogList().get(0));
		orderVo.getOrderItems().get(0).setProductNum(supplier_count_2);

		orderVo.setGoodsOwnerId(supplier_2.getGoodsOwnerId());
		orderVo.setShenqiLogisticsType(100);
		orderVo.setShenqiIdCardRequirement(0);

		placeOrderReq.setCurrency(currency);

		if (null != payChannelType)
			placeOrderReq.setPayChannelType(payChannelType);

		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 支付订单
	 * 
	 * @param userId
	 * @param tradingId
	 */
	public static Long payOrder(long userId, long tradingId) {

		return payOrder(userId, tradingId, "wxsqBuyer");
	}

	/**
	 * 支付订单
	 * 
	 * @param userId
	 * @param tradingId
	 */
	public static Long payOrder(long userId, long tradingId, String shenqiMpId) {

		return payOrder(userId, tradingId, shenqiMpId, "6000");
	}

	/**
	 * 支付订单
	 * 
	 * @param userId
	 * @param tradingId
	 * @param shenqiMpId
	 */
	public static Long payOrder(long userId, long tradingId, String shenqiMpId,
			String payType) {

		PayReq payReq = new PayReq();

		PayReqCall payReqCall = new PayReqCall();

		long thirdTradingId = 0;

		// 参数
		String tradingPassword = "abc123";
		payReq.setTradingId(tradingId);
		payReq.setUserId(userId);
		payReq.setTradingPwd(tradingPassword);
		payReq.setUserIp("103.84.20.0");
		payReq.setBankId("123");
		payReq.setPayType(payType);
		
//		payReq.setOpenId(SQPayGateWayCallService.SFTWxOpenId);
		
		if (payType.equalsIgnoreCase("6401"))
			payReq.setOpenId(SQPayGateWayCallService.WxAppOpenId);
		else
			payReq.setOpenId(isShengPay(payType) ? SQPayGateWayCallService.SFTWxOpenId
					: SQPayGateWayCallService.HipoPayWxAppOpenId);
		
		payReq.setParamExt("");
		payReq.setMemo("备注");
		payReq.setShenqiMpId(shenqiMpId);
		payReq.setVoucherUrl("http://file.iapi.ymatou.com/G01/M00/1B/BB/rBBlD19Nw_qAEoieAAAKL_CeZ3Y268_65_14_o.png");

		payReqCall.setData(false, payReq);

		try {

			Logger.comment(String.format("用户  %s, 订单支付, 交易号 %s", userId,
					tradingId));

			payReqCall.callService();

			thirdTradingId = payReqCall.getData().getLong("tradingId");
			Logger.comment(payReqCall.getData().optString("errorMessage"));

			if (payReqCall.getData().optString("errorMessage")
					.equalsIgnoreCase("账户金额不足")) {

				String accountid1 = AccountCallServiceV2
						.getAccountId((int) userId);
				AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(
						9000000), new BigDecimal(0));

				thirdTradingId = payOrder(userId, tradingId, shenqiMpId,
						payType);
			} else if (payReqCall.getData().optString("errorMessage")
					.equalsIgnoreCase("订单支付收单超时")) {
				thirdTradingId = payOrder(userId, tradingId, shenqiMpId,
						payType);
			} else if (payReqCall.getData().optString("errorMessage")
					.equalsIgnoreCase("订单支付失败")) {
				thirdTradingId = payOrder(userId, tradingId, shenqiMpId,
						payType);
			}
		} catch (Exception e) {
			Logger.info(e.toString());
			Logger.info(String.format("########支付订单 交易号:%s 异常", tradingId));
		}

		return thirdTradingId;
	}
	
	public static Long payOrderWithVirtualCoin(long userId, long tradingId,
			BigDecimal useAccountAmount) throws ClientProtocolException,
			IOException {

		PayReq payReq = new PayReq();

		PayReqCall payReqCall = new PayReqCall();

		long thirdTradingId = 0;

		// 参数
		String tradingPassword = "abc123";
		
		payReq.setTradingId(tradingId);
		payReq.setUserId(userId);
		payReq.setTradingPwd(tradingPassword);
		payReq.setUserIp("103.84.20.0");
		payReq.setBankId("123");
		payReq.setPayType("7000");
		payReq.setUseAccountAmount(useAccountAmount);

		payReq.setParamExt("");
		payReq.setMemo("备注");
		payReq.setShenqiMpId("wxsqBuyer");

		payReqCall.setData(false, payReq);
		payReqCall.callService();

		return thirdTradingId;
	}

	/**
	 * 判断是否盛付通支付
	 * 
	 * @param payType
	 * @return
	 */
	public static boolean isShengPay(String payType) {

		if (null == payType)
			return false;
		else if (payType.equalsIgnoreCase("6010")
				|| payType.equalsIgnoreCase("6011") || payType.equalsIgnoreCase("6012"))
			return true;
		else
			return false;
	}

	/**
	 * 取消订单
	 * 
	 * @param orderId
	 * @param type
	 * @param userId
	 */
	public static CancelOrderCall cancelOrder(long orderId,
			CancelOrderTypeEnum type, long userId) {

		CancelOrderReq cancelorderReq = new CancelOrderReq();
		CancelOrderCall cancelordercall = new CancelOrderCall();

		cancelorderReq.setCancelReason("自动化测试取消订单");
		cancelorderReq.setCancelType(type);
		cancelorderReq.setOrderId(orderId);
		cancelorderReq.setUserId(userId);

		cancelordercall.setData(false, cancelorderReq);
		try {

			cancelordercall.callService();

		} catch (Exception e) {
			Logger.info(String.format("########取消订单:%s 异常", orderId));
		}

		return cancelordercall;
	}

	public static String delivery(long orderId) throws ClientProtocolException,
			IOException, InterruptedException {

		return delivery(autotest_goodsOwnerId, orderId, null, null);
	}

	public static String delivery(long goodsOwnerId, long orderId, Long csId,
			Integer partialDeliveryStatus) throws ClientProtocolException,
			IOException, InterruptedException {

		SqDeliveryReq deliveryReq = new SqDeliveryReq();
		SqDeliveryCall deliveryCall = new SqDeliveryCall();
		DeliveryInfo dInfo = new DeliveryInfo();
		String billNo = TestDataManager.getRandomNum(13);

		dInfo.setOrderId(orderId);

		dInfo.setBillNo(billNo);

		// 发货节点、1国际段,2转运段,3国内段
		dInfo.setDeliverySection(1);
		dInfo.setDeliverySource(1);

		dInfo.setExpressName("sf");
		dInfo.setYmtExpressCode("Y013");
		dInfo.setPartialDeliveryStatus(partialDeliveryStatus);

		deliveryReq.setDeliveryInfos(Lists.newArrayList(dInfo));

		deliveryReq.setGoodsOwnerId(goodsOwnerId);
		deliveryReq.setCdId(csId);

		deliveryCall.setData(deliveryReq);
		deliveryCall.callService();
		
		Thread.sleep(3000);

		return billNo;
	}

	/**
	 * 操作买手备注
	 * 
	 * @param orderId
	 * @param sellerId
	 * @param type
	 *            (0:添加日志，1：更新日志)
	 * @return
	 */
	public static void operateSellerMemo(long orderId, long sellerId, int type)
			throws ClientProtocolException, IOException {

		if (type == 0) {

			AddSellerMemoReq addSellerMemoReq = new AddSellerMemoReq();
			AddSellerMemoCall addSellerMemoCall = new AddSellerMemoCall();

			addSellerMemoReq.setOrderId(orderId);
			addSellerMemoReq.setSellerId(sellerId);
			addSellerMemoReq.setSellerMemo(TestDataManager.randomStr(30)
					+ "阿斯达");
			addSellerMemoReq.setOperatorId(1);

			addSellerMemoCall.setData(addSellerMemoReq);
			addSellerMemoCall.callService();

		} else {

			UpdateShenQiSellerMemoReq updateShenQiSellerMemoReq = new UpdateShenQiSellerMemoReq();
			UpdateShenQiSellerMemoCall updateShenQiSellerMemoCall = new UpdateShenQiSellerMemoCall();

			updateShenQiSellerMemoReq.setOrderId(orderId);
			updateShenQiSellerMemoReq.setSellerId(sellerId);
			updateShenQiSellerMemoReq.setSellerMemo(TestDataManager
					.randomStr(30) + "阿斯达");
			updateShenQiSellerMemoReq.setOperatorId(1);

			updateShenQiSellerMemoCall.setData(updateShenQiSellerMemoReq);
			updateShenQiSellerMemoCall.callService();
		}
	}

	/**
	 * 根據userid 生成主单号
	 * 
	 * @param userId
	 * @return
	 */
	public static Long genMainOrderId(long userId) {

		long last4 = userId % 10000;

		GetSeqReq req = new GetSeqReq();
		GetSeqIdsCall call = new GetSeqIdsCall();

		long nativeId = 0L;

		req.setCount(1);
		req.setSeqName(String.format("main_%s", last4));

		call.setData(false, req);

		try {
			call.callService();

		} catch (Exception e) {

			e.printStackTrace();
		}

		nativeId = call.getids().get(0);

		nativeId += 100000;

		return nativeId * 10000 + last4;
	}

	/**
	 * 修改订单价格
	 * 
	 * @param orderId
	 * @param sellerId
	 * @param discount
	 * @param freight
	 */
	public static void changeDiscount(long orderId, long sellerId,
			BigDecimal discount, BigDecimal freight) {

		try {
			Logger.comment("开始修改订单折扣");
			ChangeOrderDiscountReq changeOrderDiscountReq = new ChangeOrderDiscountReq();
			ChangeOrderDiscountCall changeOrderDiscountCall = new ChangeOrderDiscountCall();

			changeOrderDiscountReq.setDiscount(discount);

			changeOrderDiscountReq.setFreight(freight);
			changeOrderDiscountReq.setOrderId(orderId);
			changeOrderDiscountReq.setSellerId(sellerId);

			// 发送请求
			changeOrderDiscountCall.setData(changeOrderDiscountReq);

			changeOrderDiscountCall.callService();

			Logger.comment("结束修改订单折扣");
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 根據mchId 获取渠道商信息
	 * 
	 * @param mchId
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static MchInfoVo getMchInfoBySellerId(Long mchId)
			throws ClientProtocolException, IOException {

		detailmchBean detailmchbean = new detailmchBean();
		detailmchCall detailmchcall = new detailmchCall();

		detailmchbean.setMchId(mchId.intValue());

		detailmchcall.setData(detailmchbean);
		detailmchcall.callService();

		return detailmchcall.getResult();
	}

	/**
	 * 判断是否为自动继承代理
	 * 
	 * @param sellerId
	 * @return
	 */
	public static Boolean isInheritedAgent(long sellerId) {

		int agentMode = 0;

		YmatouEasyCall mchDetailCall = new YmatouEasyCall("", "GET", "JSON");

		mchDetailCall
				.setUrl("http://godmch.iapi.ymatou.com/api/mch/detail?mchId="
						+ sellerId);

		try {
			mchDetailCall.callService();

			JSONObject data = new JSONObject(mchDetailCall.getReturnData())
					.optJSONObject("result");

			if (null == data)
				return false;
			else {

				agentMode = data.optInt("agentMode");
			}

		} catch (Exception e) {

			e.printStackTrace();
		}

		return agentMode == 2 ? true : false;
	}

	/**
	 * 根據sellerid 获取sellerid对应的币种
	 * 
	 * @param sellerId
	 * @return
	 */
	public static int getAllParents(long sellerId) {

		int parentId = 0;

		YmatouEasyCall mchDetailCall = new YmatouEasyCall("", "GET", "JSON");

		mchDetailCall
				.setUrl("http://godmch.iapi.ymatou.com/api/mch/allparents?mchId="
						+ sellerId);

		try {
			mchDetailCall.callService();

			JSONObject data = new JSONObject(mchDetailCall.getReturnData())
					.optJSONObject("result");

			if (null == data)
				return 0;
			else {

				Logger.debug("returndata:" + data);

				parentId = data.optJSONArray("parents").getJSONObject(0)
						.optInt("parentMchId");
			}

		} catch (Exception e) {

			e.printStackTrace();
		}

		return parentId;
	}

	/**
	 * 代购神器订单结算job
	 *
	 * @return
	 */
	public static void doSettlement() {

		YmatouEasyCall mchDetailCall = new YmatouEasyCall("", "POST", "JSON");

		mchDetailCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/doSettlement");

		mchDetailCall.setData("{}");

		try {
			mchDetailCall.callService();

			Logger.comment(mchDetailCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	/**
	 * 客服绑定
	 * 
	 * @param mchId
	 *            商户Id
	 * @param template
	 *            客服权限：1（基本权限），4（所有权限）
	 * @return
	 * @throws Exception
	 */
	public static int bindClientService(long mchId, int template) {

		int csId = 0;

		try {
			UserCreateBean usercreateBean = DGUserCallService
					.initCsUsercreateBean();
			csId = DGUserCallService.UserCreateCall(usercreateBean);
			GodmchManageCallService.CreateCSCall((int) mchId, csId, template);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Logger.comment("创建渠道商客服:" + csId);

		return csId;
	}

	public static BigDecimal calRealForeignAmount(BigDecimal realPayAmount,
			BigDecimal payableAmount, BigDecimal foreignAmount) {

		return realPayAmount.divide(payableAmount, MathContext.DECIMAL32)
				.multiply(foreignAmount);
	}

	/**
	 * 通过买入/卖出币种，进行汇率换算
	 * 
	 * @param sellAmount
	 *            卖出的价格
	 * @param buyCurrency
	 *            买入币种
	 * @param sellCurrency
	 *            卖出币种
	 * @return
	 * @throws Exception
	 */
	public static HashMap<String, BigDecimal> getAmountByCurrency(
			BigDecimal sellAmount, String buyCurrency, String sellCurrency) {

		// 先更新费率
		refreshExchangeRateConfig();

		String exchangeRate = "";
		BigDecimal amount = BigDecimal.ZERO;
		BigDecimal settleRate = BigDecimal.ZERO;
		CurrencyConfigWrapper wrapper = new CurrencyConfigWrapper();
		CurrencyConfig currencyConfig = wrapper
				.selectByPrimaryKey(sellCurrency);

		if (buyCurrency.equalsIgnoreCase("CNY"))
			exchangeRate = currencyConfig.getExchange_rmb_original_value();
		else
			exchangeRate = currencyConfig.getExchange_usd_original_value();

		String[] exhangeRateRatio = exchangeRate.split(" ");
		String currencyRatio = exhangeRateRatio[0];
		String priceRatio = exhangeRateRatio[1];

		String[] currencyRatioArray = currencyRatio.split("/");
		String[] priceRatioArray = priceRatio.split("/");
		String currencyRatioArrayLeft = currencyRatioArray[0];

		if (buyCurrency.equalsIgnoreCase(currencyRatioArrayLeft)) {

			amount = sellAmount.divide(new BigDecimal(priceRatioArray[1]), 2,
					RoundingMode.DOWN);
			settleRate = BigDecimal.ONE.divide(new BigDecimal(
					priceRatioArray[1]), 6, RoundingMode.HALF_DOWN);
		} else {

			amount = sellAmount.multiply(new BigDecimal(priceRatioArray[0]))
					.setScale(2, RoundingMode.HALF_DOWN);
			settleRate = new BigDecimal(priceRatioArray[0]);
		}

		HashMap<String, BigDecimal> map = new HashMap<String, BigDecimal>();

		map.put("amount", amount);
		map.put("settleRate", settleRate);

		return map;
	}

	/**
	 * 更新最新汇率
	 * 
	 * @return
	 */
	public static void refreshExchangeRateConfig() {

		YmatouEasyCall mchDetailCall = new YmatouEasyCall("", "POST", "JSON");

		mchDetailCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/executeRefreshExchangeRateConfigTask");

		mchDetailCall.setData("{}");

		try {
			mchDetailCall.callService();

			Logger.comment(mchDetailCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	/**
	 * 生成账户账单
	 * 
	 * @return
	 */
	public static void generateAccountDataPerDay() {

		YmatouEasyCall generateAccountDataPerDayCall = new YmatouEasyCall("",
				"POST", "JSON");

		generateAccountDataPerDayCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/generateAccountDataPerDay");

		generateAccountDataPerDayCall.setData("{}");

		try {
			generateAccountDataPerDayCall.callService();

			Logger.comment(generateAccountDataPerDayCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param userId
	 *            用户买家id
	 * @param sellerId
	 *            商家卖家id
	 * @param orderAmount
	 *            订单满多少
	 * @param sellerCouponValue
	 *            优惠券减多少
	 * @return CouponVo
	 */
	public static CouponVo createSellerCouponVo(Long userId, Long sellerId,
			BigDecimal orderAmount, BigDecimal sellerCouponValue) {

		String sellerCouponCode = TradingForDGSQCallService
				.receiveSellerCoupon(userId, sellerId, orderAmount,
						sellerCouponValue);

		if (StringUtils.isEmpty(sellerCouponCode)) {
			return null;
		}

		return createCouponVo(sellerCouponCode, sellerCouponValue);

	}

	/**
	 * createCouponVo
	 * 
	 * @return CouponVo
	 */
	public static CouponVo createCouponVo(String couponCode,
			BigDecimal couponValue) {

		CouponVo coupon = new CouponVo();

		coupon.setApplianceType(CouponApplianceTypeEnum.ALL);
		coupon.setCouponCode(couponCode);
		coupon.setCouponValue(couponValue);

		return coupon;

	}

	/**
	 * 领用商家优惠券
	 * 
	 * @param userId
	 * @param sellerId
	 * @param orderAmount
	 *            订单金额
	 * @param sellerCouponValue
	 *            优惠券减免金额
	 * @return
	 */
	public static String receiveSellerCoupon(Long userId, Long sellerId,
			BigDecimal orderAmount, BigDecimal sellerCouponValue) {

		return CouponShop2cnMCallService.receiveSellerCoupon(userId, sellerId,
				orderAmount, sellerCouponValue);
	}

	/**
	 * 订单线下支付确认
	 * 
	 * @param orderId
	 * @param sellerId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void confirmOfflinePay(long orderId, long sellerId)
			throws ClientProtocolException, IOException {

		ConfirmOfflinePayReq req = new ConfirmOfflinePayReq();

		req.setOrderId(orderId);
		req.setSellerId(sellerId);
		req.setCsId(1234L);

		ConfirmOfflinePayCall call = new ConfirmOfflinePayCall();

		call.setData(req);
		call.callService();
	}

	/**
	 * 设置用户平台费率
	 * 
	 * @return
	 */
	public static void setUserPlatformFeeSetting(Long userId, int rateId) {

		// 如果当前用户存在费率，则设置费率
		if (isExistPlatformFee(userId))
			return;
		else {

			YmatouEasyCall setUserPlatformFeeSettingCall = new YmatouEasyCall(
					"", "POST", "JSON");
			StringBuilder setUserPlatformFeeSettingString = new StringBuilder();

			setUserPlatformFeeSettingString.append("{\"userId\":" + userId);
			setUserPlatformFeeSettingString.append(", \"rateId\":" + rateId
					+ "}");

			setUserPlatformFeeSettingCall
					.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/setUserPlatformFeeSetting");

			setUserPlatformFeeSettingCall
					.setData(setUserPlatformFeeSettingString.toString());

			try {
				setUserPlatformFeeSettingCall.callService();

				Logger.comment(setUserPlatformFeeSettingCall.getReturnData());

			} catch (Exception e) {

				e.printStackTrace();
			}
		}
	}

	public static boolean isExistPlatformFee(long userId) {

		YmatouEasyCall getSellAmountListCall = new YmatouEasyCall("", "POST",
				"JSON");
		StringBuilder getSellAmountListString = new StringBuilder();

		getSellAmountListString.append("{\"userIdList\":[" + userId + "]}");

		getSellAmountListCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/getSellAmountList");

		getSellAmountListCall.setData(getSellAmountListString.toString());

		try {
			getSellAmountListCall.callService();

			Logger.comment(getSellAmountListCall.getReturnData());

			JSONObject sellAmountVo = new JSONObject(
					getSellAmountListCall.getReturnData())
					.optJSONObject("result").optJSONArray("sellAmountVoList")
					.getJSONObject(0);

			Double directSellRate = sellAmountVo.getDouble("directSellRate");
			Double proxySellRate = sellAmountVo.getDouble("proxySellRate");

			// 如果不等于默认费率，则当前用户存在费率
			if (Utils.zeroIfNull(directSellRate) != 1.2
					&& Utils.zeroIfNull(proxySellRate) != 1.6)
				return true;
			else
				return false;

		} catch (Exception e) {

			e.printStackTrace();
			return false;
		}
	}

	/**
	 * 创建盛付通代理链并将商品import给各个代理商
	 * 
	 * @param goodsOwnerId
	 *            货头Id
	 * @param n
	 *            n个中间商
	 *            是否全部开通盛付通
	 * @return AgentProductBean
	 * @throws Exception
	 */
	public static AgentProductBean createShengPayProxychain(int goodsOwnerId,
			int n) throws Exception {

		AgentProductBean agentProductBean = null;
		int parentUserId = goodsOwnerId;
		String productId = "";

		String currency = "CNY";
		productId = DGSQBaseService.createAgentProduct(goodsOwnerId,
				autotest_goodsOwnerName, true, currency);

		if (n == 0) {

			agentProductBean = new AgentProductBean();

			agentProductBean.setSellerId(parentUserId);
			agentProductBean.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo(parentUserId).get(0).getLoginId());
			agentProductBean.setProductId(productId);
			agentProductBean.setRootProductId(productId);
			agentProductBean.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			agentProductBean.setRootCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
		}

		for (int i = 0; i < n; i++) {

			// 创建一个新的渠道商并绑定上级
			createmchBean createmchBean = DGSQBaseService.bindShengPayChannel(
					parentUserId, null);

			agentProductBean = DGSQBaseService
					.importAgentProduct(createmchBean.getMchId(), "",
							productId, parentUserId, true);

			parentUserId = createmchBean.getMchId();
			productId = agentProductBean.getProductId();
			agentProductBean.setSellerId(parentUserId);
			agentProductBean.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo(createmchBean.getMchId()).get(0)
					.getLoginId());
		}

		agentProductBean.setCurrency(currency);

		return agentProductBean;
	}

	public static void ReduceSqProductStocks(long orderId)
			throws ClientProtocolException, IOException {

		ReduceSqProductStocksReq reduceSqProductStocksReq = new ReduceSqProductStocksReq();
		ReduceSqProductStocksCall reduceSqProductStocksCall = new ReduceSqProductStocksCall();

		reduceSqProductStocksReq.setOrderId(orderId);

		reduceSqProductStocksCall.setData(reduceSqProductStocksReq);
		reduceSqProductStocksCall.callService();

	}

	public static void onHpSettled(long paymentId, PaymentPo payment,
			String shengPayRate, int count) throws Exception {

		if (count < 6) {

			hpSettledReq.setTradingId(paymentId);
			hpSettledReq.setOrderAmount(payment.getRealPaidAmount());
			hpSettledReq.setSettleCurrency(payment.getSettleCurrency());
			hpSettledReq
					.setSettleAmount(payment.getRealForeignAmount() != null ? payment
							.getRealForeignAmount() : payment
							.getForeignAmount());

			if (shengPayRate != null) {

				hpSettledReq.setSettleFee(payment.getRealPaidAmount().multiply(
						new BigDecimal(shengPayRate)));
			}

			hpSettledCall.setData(hpSettledReq);
			hpSettledCall.callService();

			if (!"ok".equalsIgnoreCase(hpSettledCall.getReturnData())) {

				Thread.sleep(3000 + count * 2000);
				count++;
				onHpSettled(paymentId, payment, shengPayRate, count);
			}
		} else {

			throw new Exception();
		}
	}

	/**
	 * 修改身份证信息
	 * 
	 * @param orderId
	 * @param userId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void updateSqIdcardInfo(Long orderId, Long userId)
			throws ClientProtocolException, IOException {

		UpdateSqIdcardInfoReq updateSqIdcardInfoReq = new UpdateSqIdcardInfoReq();
		UpdateSqIdcardInfoCall updateSqIdcardInfoCall = new UpdateSqIdcardInfoCall();

		updateSqIdcardInfoReq.setOrderId(orderId);
		updateSqIdcardInfoReq.setUserId(userId);
		updateSqIdcardInfoReq.setIdcardName(TestDataManager.getChineseName());
		updateSqIdcardInfoReq.setIdcardNo(TestDataManager.getCardId(18, 1));

		updateSqIdcardInfoCall.setData(updateSqIdcardInfoReq);
		updateSqIdcardInfoCall.callService();
	}

	/**
	 * 是否免税区
	 */
	public static boolean isFreePerimeters(String address) {

		address = Utils.emptyIfNull(address);

		if (address.startsWith("香港") || address.startsWith("澳门")
				|| address.startsWith("台湾") || address.startsWith("海外"))
			return true;
		else
			return false;
	}

	public static void retryPlaceOrder(PlaceOrderCall placeorderCall, int n) {

		try {

			if (n != 3 && placeorderCall.getCode() == 500) {

				placeorderCall.callService();
				n = n + 1;

				retryPlaceOrder(placeorderCall, n);
			} else if (n == 3)
				throw new Exception("下单失败，终止下单");

		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static TradingServiceResp placeOrderWithUbuy(
			AgentProductBean productBean, UbuyUserVo ubuyUserVo) {

		PlaceOrderReq placeorderBean = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, 20238699,
						productBean, (int) autotest_goodsOwnerId);

		placeorderBean.setUbuyUserVo(ubuyUserVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeorderBean);
	}

	/**
	 * 根据满减包邮类型 下单
	 * 
	 * @param fullReductionFreeFreight
	 *            是否满减包邮
	 * @return
	 */
	public static TradingServiceResp placeOrderWithFreeFreight(
			AgentProductBean productBean, Boolean fullReductionFreeFreight) {

		PlaceOrderReq placeorderBean = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, 20238699,
						productBean, productBean.getGoodsOwnerId());

		OrderVo orderVo = placeorderBean.getOrderGroups().get(0).getOrders()
				.get(0);

		OrderItemVo orderItemVo = orderVo.getOrderItems().get(0);

		orderItemVo.setFullReductionFreeFreight(fullReductionFreeFreight);

		return TradingForDGSQCallService.callPlaceOrderService(placeorderBean);
	}

	/**
	 * 商品支付金额（不包含运费）
	 * 
	 * @param orderDetailPo
	 * @return
	 */
	public static BigDecimal getOrderDetailPaidAmountExcludeFreight(
			OrderDetailPo orderDetailPo) {
		return Utils
				.zeroIfNull(orderDetailPo.getProductPrice())
				.multiply(new BigDecimal(orderDetailPo.getProductCount()))
				.add(Utils.zeroIfNull(orderDetailPo.getDiscount()))
				.subtract(Utils.zeroIfNull(orderDetailPo.getYmtCouponAmount()))
				.subtract(
						Utils.zeroIfNull(orderDetailPo.getSellerCouponAmount()))
				.subtract(Utils.zeroIfNull(orderDetailPo.getPromotionAmount()))
				.subtract(
						Utils.zeroIfNull(orderDetailPo.getYmtPromotionAmount()))
				.subtract(Utils.zeroIfNull(orderDetailPo.getRebatePaidAmount()));
	}

	/**
	 * 1个买手,多商品,生成2个订单
	 * 
	 * @param isUserCoupon
	 *            是否使用优惠券（同时使用平台券，商家券）
	 * @return
	 * @throws Exception
	 * @throws NumberFormatException
	 */
	public static TradingServiceResp placeOrder3(boolean isUserCoupon)
			throws NumberFormatException, Exception {

		return placeOrder3(isUserCoupon,
				Long.valueOf(EnvSetup.getData("BuyUserId")),
				LogisticsTypeEnum.SailProtect);
	}

	/**
	 * 1个买手,多商品,生成2个订单
	 * 
	 * @param isUserCoupon
	 *            是否使用优惠券（同时使用平台券，商家券）
	 * @param canPayDeduct
	 *            是否使用app内立减支付金额
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder3(boolean isUserCoupon,
			boolean canPayDeduct, long userId) throws Exception {

		return placeOrder3(isUserCoupon, userId, LogisticsTypeEnum.SailProtect);
	}

	/**
	 * 1个买手,多商品,生成2个订单
	 * 
	 * @param isUserCoupon
	 *            是否使用优惠券（同时使用平台券，商家券）
	 * @param logisticsType
	 *            物流方式
	 * @return
	 * @throws Exception
	 * @throws NumberFormatException
	 */
	public static TradingServiceResp placeOrder3(boolean isUserCoupon,
			LogisticsTypeEnum logisticsType) throws NumberFormatException,
			Exception {

		return placeOrder3(isUserCoupon,
				Long.valueOf(EnvSetup.getData("BuyUserId")), logisticsType);
	}

	/**
	 * 1个买手,多商品,生成2个订单
	 * 
	 * @param isUserCoupon
	 *            是否使用优惠券（同时使用平台券，商家券）
	 * @param userId
	 *            买家用户id
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrder3(boolean isUserCoupon,
			long userId, LogisticsTypeEnum logisticsType) throws Exception {

		AgentProductBean productBean = DGSQBuildProxyChainCallService
				.createProxychain((int) autotest_goodsOwnerId, 0, false);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.TEN, userId,
						productBean, autotest_goodsOwnerId);

		// placeOrderReq.setRebatePaidAmount(BigDecimal.TEN);
		//
		// placeOrderReq.setDiscount(BigDecimal.TEN);

		// // 买手1 订单组
		OrderGroupVo groupVo1 = placeOrderReq.getOrderGroups().get(0);

		OrderItemVo orderItemVo1 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(0));

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));

		groupVo1.getOrders().get(0).getOrderItems()
				.addAll(Lists.newArrayList(orderItemVo1, orderItemVo2));
		groupVo1.getOrders().get(0).setLogisticsType(logisticsType);

		// 添加第二个订单
		AgentProductBean productBean1 = DGSQBuildProxyChainCallService
				.createProxychain((int) autotest_goodsOwnerId, 0, false);

		OrderVo OrderVo1 = TradingForDGSQCallService.createOrderVo(Lists
				.newArrayList(productBean1));

		groupVo1.getOrders().add(OrderVo1);

		if (isUserCoupon) {

			CouponVo sellerCoupon1 = TradingForDGSQCallService
					.createSellerCouponVo(userId, autotest_goodsOwnerId,
							new BigDecimal(30), BigDecimal.TEN);

			groupVo1.setSellerCoupon(sellerCoupon1);
		}

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static Boolean isCanceledOrder(OrderPo orderPo) {

		if (orderPo.getOrderStatus() == 13 || orderPo.getOrderStatus() == 12
				|| orderPo.getOrderStatus() == 18)
			return true;
		else
			return false;
	}

	public static void sellerAcceptOrder(long orderId) {

		sellerAcceptOrder(autotest_goodsOwnerId, orderId);
	}

	/**
	 * 商家接单
	 * 
	 * @param sellerId
	 * @param orderId
	 */
	public static void sellerAcceptOrder(long sellerId, long orderId) {

		AcceptOrderReq acceptorderbean = new AcceptOrderReq();

		SellerAcceptOrderCall acceptordercall = new SellerAcceptOrderCall();

		// 接单
		acceptorderbean.setOrderId(orderId);
		acceptorderbean.setSellerId(sellerId);
		acceptorderbean.setCsId(1234);

		// 发送请求
		acceptordercall.setData(false, acceptorderbean);
		try {

			Logger.comment(String.format("orderId %s, sellerId %s 接单 , ",
					orderId, sellerId));

			acceptordercall.callService();
		} catch (Exception e) {
			Logger.info(String.format("########商家接单  订单号:%s 异常", orderId));
		}
	}

	/**
	 * 
	 * @param proId
	 * @param catalogId
	 * @param isActivityPro
	 *            是否是活动商品
	 * @return
	 */
	public static int getStockNum(String proId, String catalogId,
			boolean isActivityPro) {

		int stockNum = 0;

		// try {
		// // JSONObject productInfo = GetProductInfoByProductIdCall
		// // .GetProductInfoByProductId(proId).getJSONObject("Data")
		// // .getJSONObject("Product");
		// JSONObject productInfo = getProductInfo(proId, 0);
		// JSONArray catalogList = productInfo.getJSONArray("CatalogList");
		//
		// for (int i = 0; i < catalogList.length(); i++) {
		//
		// if (catalogId.equals(catalogList.getJSONObject(i).getString(
		// "CatalogId"))) {
		//
		// // 如果是活动，返回活动库存
		// if (isActivityPro) {
		// stockNum = catalogList.getJSONObject(i).getInt(
		// "ActivityStock");
		// } else {
		// stockNum = catalogList.getJSONObject(i).getInt(
		// "CatalogStock");
		// }
		//
		// break;
		// }
		// }
		//
		// } catch (Exception e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

		return stockNum;
	}

	/**
	 * 订单确认收货
	 * 
	 * @param userId
	 * @param orderId
	 */
	public static void confirmReceive(long userId, long orderId) {

		ConfirmReceiveReq confirmReceiveReq = new ConfirmReceiveReq();
		ConfirmReceiveCall confirmreceivecall = new ConfirmReceiveCall();

		// 确认收货请求
		confirmReceiveReq.setBuyerId(userId);
		confirmReceiveReq.setOrderId(orderId);
		confirmReceiveReq.setRemark("收到了啊");
		confirmReceiveReq.setIgnoreXloboSignedCheck(true);
		// 发送请求
		confirmreceivecall.setData(false, confirmReceiveReq);
		try {
			confirmreceivecall.callService();
		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	/**
	 * 创建一个申请退款中的订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp orderApplyRefund(
			AgentProductBean productBean) throws Exception {

		TradingServiceResp placeOrderResp = TradingForDGSQCallService
				.placeOrder(productBean);

		Order order = placeOrderResp.getOrderList().get(0);

		long sellerId = order.getSellerId();
		Long userId = placeOrderResp.getUserId();

		long orderId = order.getOrderId();

		BigDecimal amount = placeOrderResp.getPayableAmount();

		// 支付订单
		Long thirdTradingId = TradingForDGSQCallService.payOrder(userId,
				placeOrderResp.getTradingId());

		// 支付网关支付回调交易
		SQPayGateWayCallService.DGSQNotifyCall(String.valueOf(thirdTradingId),
				amount.subtract(BigDecimal.ZERO).toString(), userId.intValue(),
				BigDecimal.ZERO.toPlainString());

		Thread.sleep(5000);

		// 卖家接单
		TradingForDGSQCallService.sellerAcceptOrder(sellerId, orderId);
		
		FullRefundReq fullRefundReq = new FullRefundReq();
		FullRefundCall fullRefundCall = new FullRefundCall();

		fullRefundReq.setOrderId(orderId);
		fullRefundReq.setUserId(userId);
		fullRefundReq.setCsId(1234L);
		fullRefundReq.setRemark("remar阿斯达卡");

		fullRefundCall.setData(fullRefundReq);
		fullRefundCall.callService();

		return placeOrderResp;
	}

	public static TradingServiceResp orderRefundSuccess(
			AgentProductBean productBean) throws Exception {

		return orderRefundSuccess(productBean, false);
	}

	/**
	 * 创建一个完成退款的订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp orderRefundSuccess(
			AgentProductBean productBean, Boolean isAllRefunded)
			throws Exception {

		TradingServiceResp placeOrderResp = TradingForDGSQCallService
				.placeOrder(productBean);

		Order order = placeOrderResp.getOrderList().get(0);

		long sellerId = order.getSellerId();
		Long userId = placeOrderResp.getUserId();
		OrderShardingWapper orderShardingWrapper = new OrderShardingWapper();
		long orderId = order.getOrderId();

		BigDecimal amount = placeOrderResp.getPayableAmount();

		// 支付订单
		Long thirdTradingId = TradingForDGSQCallService.payOrder(userId,
				placeOrderResp.getTradingId());

		// 支付网关支付回调交易
		SQPayGateWayCallService.DGSQNotifyCall(String.valueOf(thirdTradingId),
				amount.subtract(BigDecimal.ZERO).toString(), userId.intValue(),
				BigDecimal.ZERO.toPlainString());

		Thread.sleep(5000);

		Long paymentId = orderShardingWrapper.selectOrderbyOrderId(orderId)
				.getPaymentId();

		// 卖家接单
		TradingForDGSQCallService.sellerAcceptOrder(sellerId, orderId);
		
		if (isAllRefunded)
			RefundService.createFullRefundSuccess(orderId, productBean.getGoodsOwnerId(), paymentId, userId);
		else
			RefundService.createPartProductRefundSuccess(orderId, order.getOrderDetailPoList().get(0),
					productBean.getGoodsOwnerId(), paymentId, userId);

		// 退款提交到网关
		UserRefundFundDetailPo record = new UserRefundFundDetailPo();

		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.MINUTE, -6);

		record.setPaymentId(paymentId);
		record.setUpdateTime(calendar.getTime());

		orderShardingWrapper.userRefundFundDetailMapper
				.updateByPrimaryKeySelective(record);

		RefundService.supplementRefund(orderId);

		// 支付网关退款回调
		SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
				userId.intValue());

		return placeOrderResp;
	}

	/**
	 * 创建一个完成失败的订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp orderRefundFailed(
			AgentProductBean productBean) throws Exception {

		TradingServiceResp placeOrderResp = TradingForDGSQCallService
				.placeOrder(productBean);

		Order order = placeOrderResp.getOrderList().get(0);

		long sellerId = order.getSellerId();
		Long userId = placeOrderResp.getUserId();
		OrderShardingWapper orderShardingWrapper = new OrderShardingWapper();
		long orderId = order.getOrderId();

		BigDecimal amount = placeOrderResp.getPayableAmount();

		// 支付订单
		Long thirdTradingId = TradingForDGSQCallService.payOrder(userId,
				placeOrderResp.getTradingId());

		// 支付网关支付回调交易
		SQPayGateWayCallService.DGSQNotifyCall(String.valueOf(thirdTradingId),
				amount.subtract(BigDecimal.ZERO).toString(), userId.intValue(),
				BigDecimal.ZERO.toPlainString());

		Thread.sleep(5000);

		Long paymentId = orderShardingWrapper.selectOrderbyOrderId(orderId)
				.getPaymentId();

		// 卖家接单
		TradingForDGSQCallService.sellerAcceptOrder(sellerId, orderId);

		// 修改结算单结算金额小于退款金额
		new OrderSettlementDetailWrapper()
				.UpdateTotalRMBAmountByOrderIdAndUserId(orderId, sellerId,
						BigDecimal.ONE);

		RefundService.createFullRefundFailed(orderId, productBean.getGoodsOwnerId(), paymentId, userId);
		
		return placeOrderResp;
	}

	/**
	 * 创建一个申请退款中的订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp orderApplyRefund(
			TradingServiceResp placeOrderResp, Integer refundCount)
			throws Exception {

		Long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
		Long goodsOwnerId = placeOrderResp.getOrderList().get(0).getOrderPo()
				.getGoodsOwnerId();

		String refundedCatalogId = placeOrderResp.getOrderList().get(0)
				.getOrderDetailPoList().get(0).getCatalogId();

		if (null == refundCount)
			refundCount = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getProductCount();

		HashMap<String, BigDecimal> map = RefundService.getShenqiRefundAmount(
				orderId, goodsOwnerId, refundedCatalogId, refundCount);

		ConfirmApplyRefundReq req = RefundService.buildStandApplyRefundReq(
				orderId, goodsOwnerId, refundedCatalogId,
				map.get("maxRefundFreight"), map.get("maxRefundTax"),
				map.get("maxProductRefundAmount"), refundCount);

		RefundService.applyRefundCall(req);

		return placeOrderResp;
	}

	/**
	 * 创建一个整单退款的订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp entireOrderApplyRefund(
			TradingServiceResp placeOrderResp) throws Exception {

		Long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
		Long goodsOwnerId = placeOrderResp.getOrderList().get(0).getOrderPo()
				.getGoodsOwnerId();

		HashMap<String, BigDecimal> map = RefundService.getShenqiRefundAmount(
				orderId, goodsOwnerId, null, null);

		ConfirmApplyRefundReq req = RefundService.buildStandApplyRefundReq(
				orderId, goodsOwnerId, null, map.get("maxRefundFreight"),
				map.get("maxRefundTax"), map.get("maxProductRefundAmount"),
				null);

		RefundService.applyRefundCall(req);

		return placeOrderResp;
	}

	/**
	 * 创建一个所有商品都退款的订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp allOrderItemApplyRefund(
			TradingServiceResp placeOrderResp, Integer refundCount, Long paymentId)
			throws Exception {

		Long userId = placeOrderResp.getUserId();

		for (Order order : placeOrderResp.getOrderList()) {

			Long orderId = order.getOrderId();
			Long goodsOwnerId = order.getOrderPo().getGoodsOwnerId();

			for (OrderDetailPo orderDetailPo : order.getOrderDetailPoList()) {

				if (null == refundCount) {

					RefundService.createOnePartProductRefundSuccess(orderId,
							orderDetailPo, goodsOwnerId, paymentId, userId,
							orderDetailPo.getProductCount());
				} else {

					RefundService.createOnePartProductRefundSuccess(orderId,
							orderDetailPo, goodsOwnerId, paymentId, userId,
							refundCount);
				}

				Thread.sleep(3000);
			}
		}

		return placeOrderResp;
	}

	/**
	 * 码头保存发货物流单号
	 * 
	 * @param orderId
	 * @param sellerId
	 * @param billCode
	 */
	public static void saveDeliverSummary(long orderId, long sellerId,
			String billCode) {

		try {
			YmatouEasyCall SaveDeliverSummaryCall = new YmatouEasyCall("",
					"POST", "JSON");
			StringBuffer saveDeliverSummaryString = new StringBuffer();
			saveDeliverSummaryString
					.append("{\"SaveDeliverSummaryInfos\":[{\"BillCode\":\"");
			saveDeliverSummaryString.append(billCode);
			saveDeliverSummaryString.append("\",");
			saveDeliverSummaryString
					.append("\"CanReDelivery\":0,\"CatalogStatus\":\"7\",\"DeliverType\":2,\"ExpressCode\":\"xlobo\",\"InnerExpressCode\":\"\",\"IsChinaDeliver\":true,");
			saveDeliverSummaryString.append("\"OrderId\":");
			saveDeliverSummaryString.append(orderId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString
					.append("\"Provider\":\"洋码头官方合作物流（xLobo贝海国际速递）\",");
			saveDeliverSummaryString.append("\"SellerId\":");
			saveDeliverSummaryString.append(sellerId);
			saveDeliverSummaryString.append(",");
			saveDeliverSummaryString.append("\"Weight\":10}]}");
			SaveDeliverSummaryCall
			// .setUrl("http://orderdelivery.iapi.ymatou.com/api/Deliver/SaveDeliverSummary");
					.setUrl("http://api.seller.ymatou.com/api/Deliver/SaveDeliverSummary");

			SaveDeliverSummaryCall.setData(saveDeliverSummaryString.toString());

			Logger.comment("发货保存运单号");
			SaveDeliverSummaryCall.callService();

		} catch (Exception e) {
			// TODO: handle exception
		}

	}

	/**
	 * 锁定，解锁订单
	 * 
	 * @param orderId
	 * @param islock
	 *            1 锁定 , 非1 解锁
	 */
	public static void markOrderLock(long orderId, int islock) {

		MarkOrderLockReq markOrderLockReq = new MarkOrderLockReq();
		MarkOrderLockCall markOrderLockCall = new MarkOrderLockCall();

		// 参数
		markOrderLockReq.setOrderId(orderId);
		markOrderLockReq.setLockStatus(islock);

		// 发送请求
		markOrderLockCall.setData(false, markOrderLockReq);

		try {
			markOrderLockCall.callService();
		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	public static Boolean getMchSupportHpCNY(long goodsOwnerId)
			throws Exception {

		YmatouEasyCall getMchSupportHpCNYCall = new YmatouEasyCall("", "POST",
				"JSON");
		StringBuilder getMchSupportHpCNYString = new StringBuilder();

		getMchSupportHpCNYString.append("{\"mchId\":" + goodsOwnerId + "}");

		getMchSupportHpCNYCall
				.setUrl("http://godmch.iapi.ymatou.com/api/config/getMchRiskConfig");

		getMchSupportHpCNYCall.setData(getMchSupportHpCNYString.toString());

		getMchSupportHpCNYCall.callService();

		Logger.comment(getMchSupportHpCNYCall.getReturnData());

		JSONObject result = new JSONObject(
				getMchSupportHpCNYCall.getReturnData()).optJSONObject("result");

		if (result.isNull("supportHpCNY"))
			return null;
		else {

			return result.optBoolean("supportHpCNY");
		}
	}

	public static void executeCancelProviderSettlementDetailTask()
			throws Exception {

		YmatouEasyCall executeCancelProviderSettlementDetailTaskCall = new YmatouEasyCall(
				"", "POST", "JSON");
		StringBuilder executeCancelProviderSettlementDetailTaskString = new StringBuilder();

		executeCancelProviderSettlementDetailTaskString.append("{}");

		executeCancelProviderSettlementDetailTaskCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/executeCancelProviderSettlementDetailTask");

		executeCancelProviderSettlementDetailTaskCall
				.setData(executeCancelProviderSettlementDetailTaskString
						.toString());

		executeCancelProviderSettlementDetailTaskCall.callService();

		Thread.sleep(3000);
	}

	/**
	 * 商品入库
	 * 
	 * @param goodsOwnerId
	 * @param productId
	 * @param num
	 * @throws IOException
	 */
	public static void stockIn(long goodsOwnerId, String productId, int num)
			throws IOException {
		Shop2cnStockCallService.stockIn((int) autotest_goodsOwnerId, productId,
				num);
	}

	/**
	 * 核销虚拟库存通知
	 * 
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void sqStockChangeNotify(AgentProductBean productBean)
			throws ClientProtocolException, IOException {

		SqStockChangeNotifyReq sqStockChangeNotifyReq = new SqStockChangeNotifyReq();
		SqStockChangeNotifyCall sqStockChangeNotifyCall = new SqStockChangeNotifyCall();

		sqStockChangeNotifyReq.setCatalogId(productBean.getRootCatalogList()
				.get(0));
		sqStockChangeNotifyReq.setSellerId(productBean.getGoodsOwnerId());

		sqStockChangeNotifyCall.setData(sqStockChangeNotifyReq);
		sqStockChangeNotifyCall.callService();
	}

	/**
	 * 1个买手,1个商品,生成单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithProxyOrderId(
			AgentProductBean productBean) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId, false);
		placeOrderReq.setProxyOrderId(TestDataManager.getRandomIntNum(8));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp placeOrderWithServiceRate(
			AgentProductBean productBean) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, 20238699,
						productBean, autotest_goodsOwnerId, false);
		placeOrderReq.getOrderGroups().get(0)
				.setServiceRate(new BigDecimal("7.00"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static TradingServiceResp placeOrderWithServiceRate(
			AgentProductBean productBean, Boolean supportOfflinePay,
			String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, productBean.getGoodsOwnerId(), false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.13"));
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		placeOrderReq.setCurrency(currency);

		placeOrderReq.setSupportOfflinePay(supportOfflinePay);

		placeOrderReq.getOrderGroups().get(0)
				.setServiceRate(new BigDecimal("7.00"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 返回单个商品的服务费
	 * 
	 * @param orderDetailPo
	 * @return
	 */
	public static BigDecimal getServiceAmount(OrderDetailPo orderDetailPo) {

		BigDecimal serviceAmount = (orderDetailPo.getProductPrice()
				.add(orderDetailPo.getTaxFee()))
				.multiply(new BigDecimal(orderDetailPo.getProductCount()))
				.add(orderDetailPo.getDiscount())
				.add(Utils.falseIfNull(orderDetailPo
						.getFullReductionFreeFreight()) ? BigDecimal.ZERO
						: orderDetailPo.getFreight())
				.subtract(orderDetailPo.getSellerCouponAmount())
				.subtract(orderDetailPo.getPromotionAmount());

		return serviceAmount.multiply(orderDetailPo.getServiceRate())
				.multiply(new BigDecimal("0.01"))
				.setScale(2, BigDecimal.ROUND_HALF_DOWN);
	}

	/**
	 * 修改商品sku
	 * 
	 * @param orderId
	 * @param catalogId
	 * @param productBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void updateOrderProductSku(Long orderId, String catalogId,
			AgentProductBean productBean) throws ClientProtocolException,
			IOException {

		UpdateOrderProductSkuReq updateOrderProductSkuReq = new UpdateOrderProductSkuReq();
		UpdateOrderProductSkuCall updateOrderProductSkuCall = new UpdateOrderProductSkuCall();

		updateOrderProductSkuReq.setOrderId(orderId);
		updateOrderProductSkuReq.setCatalogId(catalogId);
		updateOrderProductSkuReq.setOperatorId(productBean.getSellerId());
		updateOrderProductSkuReq.setSku(TestDataManager.getRandomNum(8));
		updateOrderProductSkuReq.setSellerId(productBean.getSellerId());

		updateOrderProductSkuCall.setData(updateOrderProductSkuReq);
		updateOrderProductSkuCall.callService();
	}

	/**
	 * 修改订单发货时间
	 * 
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void updateOrderDeliveryTime(Long orderId,
			AgentProductBean productBean) throws ClientProtocolException,
			IOException {

		UpdateOrderDeliveryTimeReq updateOrderDeliveryTimeReq = new UpdateOrderDeliveryTimeReq();
		UpdateOrderDeliveryTimeCall updateOrderDeliveryTimeCall = new UpdateOrderDeliveryTimeCall();

		updateOrderDeliveryTimeReq.setOrderId(orderId);
		updateOrderDeliveryTimeReq.setSellerId(productBean.getGoodsOwnerId());
		updateOrderDeliveryTimeReq.setNewDeliveryTime(YMTDateUtil
				.getBeforeOrNextHour(YMTDateUtil.getDate(), 1));
		updateOrderDeliveryTimeReq.setOperatorId(1234L);

		updateOrderDeliveryTimeCall.setData(updateOrderDeliveryTimeReq);
		updateOrderDeliveryTimeCall.callService();
	}

	/**
	 * 创建一个退款失败的结算单
	 * 
	 * @param orderId
	 * @return
	 */
	public static void onRefundFailEvent(Long orderId, String refundId) {

		YmatouEasyCall onRefundFailEventCall = new YmatouEasyCall("", "POST",
				"JSON");
		StringBuilder onRefundFailEventString = new StringBuilder();

		onRefundFailEventString.append("{\"orderId\": " + orderId + ", ");
		onRefundFailEventString.append("\"refundId\": \"" + refundId + "\"}");

		onRefundFailEventCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/onRefundFailEvent");

		onRefundFailEventCall.setData(onRefundFailEventString.toString());

		try {
			onRefundFailEventCall.callService();

			Logger.comment(onRefundFailEventCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	/**
	 * 退款失败结算单进行结算
	 */
	public static void executeRefundFailSettlementTask() {

		YmatouEasyCall executeRefundFailSettlementTaskCall = new YmatouEasyCall(
				"", "POST", "JSON");

		executeRefundFailSettlementTaskCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/executeRefundFailSettlementTask");

		executeRefundFailSettlementTaskCall.setData("{}");

		try {
			executeRefundFailSettlementTaskCall.callService();

			Logger.comment(executeRefundFailSettlementTaskCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	/**
	 * 代购神器分销裂变结算
	 *
	 * @return
	 */
	public static void executeProxyFissionSettlementTask() {

		YmatouEasyCall executeProxyFissionSettlementTaskCall = new YmatouEasyCall(
				"", "POST", "JSON");

		executeProxyFissionSettlementTaskCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/executeProxyFissionSettlementTask");

		executeProxyFissionSettlementTaskCall.setData("{}");

		try {
			executeProxyFissionSettlementTaskCall.callService();

			Logger.comment(executeProxyFissionSettlementTaskCall
					.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	public static void saveProxyFissionConfigCall(
			SaveProxyFissionConfigReq saveProxyFissionConfigReq)
			throws ClientProtocolException, IOException {

		SaveProxyFissionConfigCall saveProxyFissionConfigCall = new SaveProxyFissionConfigCall();

		saveProxyFissionConfigCall.setData(saveProxyFissionConfigReq);
		saveProxyFissionConfigCall.callService();
	}

	/**
	 * 带有用户直播上报的下单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithUserClick(
			AgentProductBean productBean, Long goodsOwnerId,
			Boolean isBefore3Hour) throws Exception {
		
		Long sellerId = productBean.getSellerId();
		String productId = productBean.getProductId();
		
		// 直播点击上报
		SqUserClickService.userClick(20238699L, sellerId,
				productId);

		if (isBefore3Hour)
			SqUserClickService.updateUserClickAddTime(
					20238699L, sellerId, productId,
					YMTDateUtil.getBeforeOrNextHour(-3));

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithUserClickAndIntegral(
			AgentProductBean productBean, Long goodsOwnerId, Long integral,
			Boolean isBefore3Hour) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		OrderVo orderVo = placeOrderReq.getOrderGroups().get(0).getOrders()
				.get(0);

		Long sellerId = placeOrderReq.getOrderGroups().get(0).getSellerId();
		String productId = placeOrderReq.getOrderGroups().get(0).getOrders()
				.get(0).getOrderItems().get(0).getProductId();

		orderVo.getOrderItems().add(
				TradingForDGSQCallService.createOrderItemVo(productBean
						.getProductId(), productBean.getCatalogList().get(1)));

		// 直播点击上报
		SqUserClickService.userClick(placeOrderReq.getUserId(), sellerId,
				productId);

		if (isBefore3Hour)
			SqUserClickService.updateUserClickAddTime(
					placeOrderReq.getUserId(), sellerId, productId,
					YMTDateUtil.getBeforeOrNextHour(-3));
		
		placeOrderReq.setIntegral(integral);
		placeOrderReq.setShenqiProxyBuyOrder(true);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 创建活动商品订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithActivity(
			AgentProductBean productBean, Long goodsOwnerId) throws Exception {

		TradingForDGSQCallService.agentProductAddActivity(productBean, false);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, goodsOwnerId);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}

	public static Integer agentProductAddActivity(AgentProductBean productBean, Boolean useSubCode)
			throws ClientProtocolException, IOException {

		// 创建活动商品
		AddactivityBean addactivityBean = AgentProductCallServiceV2
				.initProductaddactivity((int) productBean.getSellerId(),
						productBean.getProductId(), 1, 5, useSubCode);

		addactivityBean.setDiscountType(1);
		addactivityBean
				.getProductList()
				.get(0)
				.getCatalogList()
				.stream()
				.forEach(catalog -> {
					// catalog.setDiscount(catalog);
						catalog.setDiscountPrice(new BigDecimal(new Random()
								.nextInt(20) + 1201));
					});

		return AgentProductCallServiceV2
				.agentProductaddactivity(addactivityBean);
	}
	
	public static Integer agentProductListAddActivity(List<AgentProductBean> productBeanList)
			throws ClientProtocolException, IOException {

		// 创建活动商品
		AddactivityBean addactivityBean = AgentProductCallServiceV2
				.initProductaddactivity((int) productBeanList.get(0).getSellerId(),
						productBeanList.get(0).getProductId());

		addactivityBean.setDiscountType(1);
		
		addactivityBean
				.getProductList()
				.get(0)
				.getCatalogList()
				.stream()
				.forEach(catalog -> {
					// catalog.setDiscount(catalog);
						catalog.setDiscountPrice(new BigDecimal(new Random()
								.nextInt(20) + 1201));
					});
		
		for (int i = 1; i < productBeanList.size(); i++) {
			
			ProductAgentBean productAgentBean = new ProductAgentBean();
			AgentProductBean agentProductBean = productBeanList.get(i);
			
			productAgentBean.setProductId(agentProductBean.getProductId());
			
			List<String> catalogList = new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService
					.selectProductDetails((int) agentProductBean.getSellerId(),
							agentProductBean.getProductId());
			selectProductDetails.getCatalogList().forEach(a -> {
				catalogList.add(a.getCatalogId());
			});

			List<CatalogAgentBean> list1 = new ArrayList<CatalogAgentBean>();
			catalogList.forEach(e -> {
				CatalogAgentBean c = new CatalogAgentBean();
				c.setCatalogId(e);
				c.setDiscount(new BigDecimal("2"));// 折扣，例如：8.5折，值为：8.5
					c.setDiscountPrice(new BigDecimal(
							new Random().nextInt(20) + 1201));
					c.setActivityStock(null);
					list1.add(c);
				});
			
			productAgentBean.setCatalogList(list1);
			
			addactivityBean.getProductList().add(productAgentBean);	
		}
		
		return AgentProductCallServiceV2
				.agentProductaddactivity(addactivityBean);
	}

	/**
	 * 修改支付凭证
	 * 
	 * @param mainOrderId
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static void UpdateVoucher(Long mainOrderId, Long userId)
			throws ClientProtocolException, IOException {

		UpdateVoucherReq updateVoucherReq = new UpdateVoucherReq();
		UpdateVoucherCall updateVoucherCall = new UpdateVoucherCall();

		updateVoucherReq.setVoucherUrl(TestDataManager.randomStr(10));
		updateVoucherReq.setMainOrderId(mainOrderId);
		updateVoucherReq.setUserId(userId);

		updateVoucherCall.setData(updateVoucherReq);
		updateVoucherCall.callService();
	}

	/**
	 * 直销商创建一个组合商品订单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeComposeProductOrder(
			AgentProductBean productBean, long sellerId) {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean, sellerId, true, false);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setProdTaxRate(new BigDecimal("0.17"));
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setSubProduct(true);

		// 商家券
		CouponVo sellerCoupon1 = TradingForDGSQCallService
				.createSellerCouponVo(placeOrderReq.getUserId(), sellerId,
						new BigDecimal(30), BigDecimal.TEN);

		placeOrderReq.getOrderGroups().get(0).setSellerCoupon(sellerCoupon1);
		placeOrderReq.setDiscount(BigDecimal.TEN.negate());

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 直销商创建多个组合商品订单
	 * 
	 * @return
	 * @throws Exception 
	 */
	public static TradingServiceResp placeMultiComposeProductOrderWithIntegral(long goodsOwnerId) throws Exception {

		Integer mchId = DGSQBaseService.createIndependenceMch("USA");
		AgentProductBean productBean1 = DGSQBuildProxyChainCallService
				.createComposeProductProxychain(
						(int) goodsOwnerId, false, false);
		
		Long shopId1 = productBean1.getSellerId(); 
		
		GodPointsService.saveCreditPolicyReq((long)shopId1);
		Thread.sleep(500);
		
		GodPointsService.sendCredit((long)shopId1, 20238699L);
		Thread.sleep(500);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						productBean1, productBean1.getSellerId(), false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		orderItemVo1.setSubProduct(true);
		orderItemVo1.setProdTaxRate(new BigDecimal("0.17"));

		AgentProductBean productBean2 = DGSQBuildProxyChainCallService
				.createComposeProductProxychain(
						(int) mchId, false, false);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean2.getRootProductId(),
						productBean2.getCatalogList().get(0));

		orderItemVo2.setSubProduct(true);
		orderItemVo2.setProdTaxRate(new BigDecimal("0.12"));

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setRegionDiscountRatio(new BigDecimal("6.00"));

		placeOrderReq.setShenqiProxyBuyOrder(true);
		
		placeOrderReq.setIntegral(10L);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeCDFMemberComposeProductOrder(
			long cdfMembergoodsOwnerId, long integral) throws Exception {

		AgentProductBean productBean1 = DGSQBuildProxyChainCallService
				.createComposeProductProxychain((int) cdfMembergoodsOwnerId,
						false, false);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 26080783,
						productBean1, productBean1.getSellerId(), false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		orderItemVo1.setSubProduct(true);
		orderItemVo1.setSku("C052901");
		
		orderItemVo1.setProductPrice(new BigDecimal("369.00"));
		orderItemVo1.setProductNum(1);
		orderItemVo1.setFreight(BigDecimal.ZERO);

		AgentProductBean productBean2 = DGSQBuildProxyChainCallService
				.createComposeProductProxychain((int) cdfMembergoodsOwnerId,
						false, false);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService.createOrderItemVo(
				productBean2.getRootProductId(), productBean2.getCatalogList()
						.get(0));

		orderItemVo2.setSubProduct(true);
		orderItemVo2.setSku("C052900");

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		placeOrderReq.setIntegral(integral);
		placeOrderReq.setIntegralServiceType(2);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeMultiCodeComposeProductOrder(
			long multiCDFCodeGoodsOwnerId) throws Exception {

		AgentProductBean productBean = DGSQBuildProxyChainCallService
				.createComposeProductProxychain(
						(int) multiCDFCodeGoodsOwnerId, false, true);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO, 26080783,
						productBean, (int) multiCDFCodeGoodsOwnerId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setSubProduct(true);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeYabandOrder(AgentProductBean productBean,
			long goodsOwnerId, String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setPayChannelType(3);
		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeChainStoreOrder(AgentProductBean productBean,
			long goodsOwnerId, String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0L, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setPayChannelType(4);
		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeChainStoreOrderWithUserId(AgentProductBean productBean,
			long goodsOwnerId, String currency, Long userId) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setPayChannelType(4);
		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 下一个抖音订单
	 * @param productBean
	 * @param goodsOwnerId
	 * @param currency
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeDouYinOrder(AgentProductBean productBean,
			long goodsOwnerId, String currency) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0L, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(null);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setCurrency(currency);
		
		placeOrderReq.setPlaceOrderSource("ShenqiDouyinMp");

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeDouYinOrderWithIntegral(AgentProductBean productBean,
			long goodsOwnerId, String currency, Long integral) throws Exception {

		int userId = new OrderCallService().createNewUser();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0L, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(null);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setCurrency(currency);
		
		placeOrderReq.setPlaceOrderSource("ShenqiDouyinMp");
		placeOrderReq.setIntegral(integral);
		placeOrderReq.setShenqiProxyBuyOrder(true);
		
		GodPointsService.sendCredit(productBean.getSellerId(), (long)userId);
		Thread.sleep(500);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 带有用户直播上报的下单,第一个AgentProductBean才上报
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithUserClickPartProduct(
			List<AgentProductBean> productBeanList, Long goodsOwnerId,
			Boolean isBefore3Hour) throws Exception {

		AgentProductBean bean1 = productBeanList.get(0);
		AgentProductBean bean2 = productBeanList.get(1);
		
		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.ZERO, 20238699,
						bean1, goodsOwnerId);

		OrderVo orderVo = placeOrderReq.getOrderGroups().get(0).getOrders()
				.get(0);

		Long sellerId = placeOrderReq.getOrderGroups().get(0).getSellerId();
		String productId = placeOrderReq.getOrderGroups().get(0).getOrders()
				.get(0).getOrderItems().get(0).getProductId();

		orderVo.getOrderItems().add(
				TradingForDGSQCallService.createOrderItemVo(bean1
						.getProductId(), bean1.getCatalogList().get(1)));

		orderVo.getOrderItems().add(
				TradingForDGSQCallService.createOrderItemVo(bean2
						.getProductId(), bean2.getCatalogList().get(0)));
		
		// 直播点击上报
		SqUserClickService.userClick(placeOrderReq.getUserId(), sellerId,
				bean1.getProductId());

		if (isBefore3Hour)
			SqUserClickService.updateUserClickAddTime(
					placeOrderReq.getUserId(), sellerId, productId,
					YMTDateUtil.getBeforeOrNextHour(-3));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 1个买手,1个商品带有成本价,单个订单
	 * 
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithPrimeCostPrice(
			AgentProductBean productBean, long goodsOwnerId) throws Exception {

		// int userId = new OrderCallService().createNewUser();
		int userId = 20238699;

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().get(0).setPrimeCostPrice(new BigDecimal("15.21"));
		
//		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
//				.getOrderItems().get(0)
//				.setPrimeCostPrice(BigDecimal.ZERO);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOrderWithIntegral(
			AgentProductBean productBean, long goodsOwnerId, Long integral) throws Exception {

		return placeOrderWithIntegralAndCurrency(productBean, goodsOwnerId, integral, null);
	}
	
	public static TradingServiceResp placeOrderWithIntegralAndCurrency(
			AgentProductBean productBean, long goodsOwnerId, Long integral, String currency) throws Exception {

		int userId = 20238699;

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.setIntegral(integral);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setShenqiProxyBuyOrder(true);
		placeOrderReq.setCurrency(currency);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 单个换购商品下单
	 * @param productBean
	 * @param goodsOwnerId
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithExchangeBuy(
			AgentProductBean productBean, long goodsOwnerId) throws Exception {

		Integer activityId = TradingForDGSQCallService
				.agentProductAddActivity(productBean, false);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.TEN, 20238699,
						productBean, goodsOwnerId, false);

		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		orderItemVo1.setProductNum(1);
		orderItemVo1.setPrimeCostPrice(BigDecimal.TEN);

//		ActivityVo activityVo = new ActivityVo();
//
//		activityVo.setActivityId(activityId);
//		activityVo.setActivityTemplateId(5123);
//		activityVo.setAfterActivityFinishAccept(true);
//		activityVo.setProductInActivityId(1234);

//		orderItemVo1.setActivity(activityVo);
		orderItemVo1.setExchangeBuyActivityId(activityId);

		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		orderItemVo2.setExchangeBuy(true);

//		orderItemVo2.setActivity(activityVo);
		orderItemVo2.setExchangeBuyActivityId(activityId);

		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 换购商品+普通商品下单
	 * @param activityProductBeanList
	 * @param normalProductBean
	 * @param goodsOwnerId
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithExchangeBuyList(
			List<AgentProductBean> activityProductBeanList,
			AgentProductBean normalProductBean, long goodsOwnerId)
			throws Exception {

		Integer activityId = TradingForDGSQCallService
				.agentProductListAddActivity(activityProductBeanList);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.TEN, 20238699,
						normalProductBean, goodsOwnerId, false);

//		ActivityVo activityVo = new ActivityVo();
//
//		activityVo.setActivityId(activityId);
//		activityVo.setActivityTemplateId(5123);
//		activityVo.setAfterActivityFinishAccept(true);
//		activityVo.setProductInActivityId(1234);
		
		for (int i = 0; i < activityProductBeanList.size(); i++) {
			
			AgentProductBean agentProductBean = activityProductBeanList.get(i);
			
			OrderItemVo orderItemVo = TradingForDGSQCallService
					.createOrderItemVo(agentProductBean.getProductId(),
							agentProductBean.getCatalogList().get(0));

			if (i == activityProductBeanList.size() - 1)
				orderItemVo.setExchangeBuy(true);
			
			orderItemVo.setExchangeBuyActivityId(activityId);

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVo);
		}

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 多个换购商品下单
	 * @param activityProductBeanListLetter 4个以上商品
	 * @param activityProductBeanListNum 4个以上商品
	 * @param normalProductBean
	 * @param goodsOwnerId
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithMultiExchangeBuyList(
			List<AgentProductBean> activityProductBeanListLetter,
			List<AgentProductBean> activityProductBeanListNum, AgentProductBean normalProductBean, long goodsOwnerId)
			throws Exception {

		Integer activityId = TradingForDGSQCallService
				.agentProductListAddActivity(activityProductBeanListLetter);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(0, BigDecimal.TEN, 20238699,
						normalProductBean, goodsOwnerId, false);

//		ActivityVo activityVo = new ActivityVo();
//
//		activityVo.setActivityId(activityId);
//		activityVo.setActivityTemplateId(5123);
//		activityVo.setAfterActivityFinishAccept(true);
//		activityVo.setProductInActivityId(1234);
		
		for (int i = 0; i < activityProductBeanListLetter.size(); i++) {
			
			AgentProductBean agentProductBean = activityProductBeanListLetter.get(i);
			
			OrderItemVo orderItemVo = TradingForDGSQCallService
					.createOrderItemVo(agentProductBean.getProductId(),
							agentProductBean.getCatalogList().get(0));

			if (i == activityProductBeanListLetter.size() - 1
					|| i == activityProductBeanListLetter.size() - 2)
				orderItemVo.setExchangeBuy(true);
			
//			orderItemVo.setActivity(activityVo);
			orderItemVo.setExchangeBuyActivityId(activityId);

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVo);
		}
		
		activityId = TradingForDGSQCallService
				.agentProductListAddActivity(activityProductBeanListNum);
		
//		activityVo = new ActivityVo();
//
//		activityVo.setActivityId(activityId);
//		activityVo.setActivityTemplateId(5123);
//		activityVo.setAfterActivityFinishAccept(true);
//		activityVo.setProductInActivityId(1234);
		
		for (int i = 0; i < activityProductBeanListNum.size(); i++) {
			
			AgentProductBean agentProductBean = activityProductBeanListNum.get(i);
			
			OrderItemVo orderItemVo = TradingForDGSQCallService
					.createOrderItemVo(agentProductBean.getProductId(),
							agentProductBean.getCatalogList().get(0));

			if (i == activityProductBeanListNum.size() - 1
					|| i == activityProductBeanListNum.size() - 2)
				orderItemVo.setExchangeBuy(true);
			
//			orderItemVo.setActivity(activityVo);
			orderItemVo.setExchangeBuyActivityId(activityId);

			placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
					.getOrderItems().add(orderItemVo);
		}

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 修改订单地址
	 * @param orderId
	 * @param userId
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void changeOrderAddress(Long orderId, Long userId)
			throws ClientProtocolException, IOException {

		ChangeOrderAddressReq changeOrderAddressReq = new ChangeOrderAddressReq();
		ChangeOrderAddressCall changeOrderAddressCall = new ChangeOrderAddressCall();

		changeOrderAddressReq.setAddress("南京路步行街");
		changeOrderAddressReq.setOrderId(orderId);
		changeOrderAddressReq.setPhone(139 + TestDataManager.getRandomNum(8));
		changeOrderAddressReq.setPostCode("986574");
		changeOrderAddressReq.setReceievePerson("海鲲科技");
		changeOrderAddressReq.setUserId(userId);
		changeOrderAddressReq.setUserType(UserTypeEnum.Normal);

		changeOrderAddressCall.setData(changeOrderAddressReq);
		changeOrderAddressCall.callService();
	}
	
	public static TradingServiceResp placeOrderWithCDFMember(
			AgentProductBean productBean, long goodsOwnerId, Long integral) throws Exception {

		int userId = 26080783;
		
		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);
		
		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		
		orderItemVo.setSku("C052901");
		orderItemVo.setProductRecordNo("C052901");	 
		
		orderItemVo.setProductPrice(new BigDecimal("110.00"));
		orderItemVo.setProductNum(3);
		orderItemVo.setFreight(BigDecimal.ZERO);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.setIntegral(integral);
		placeOrderReq.setIntegralServiceType(2);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		
//		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
//				.setShenqiLogisticsType(4);
//		placeOrderReq.getOrderGroups().get(0).getOrders().get(0).setShenqiIdCardRequirement(1);
//		placeOrderReq.getOrderGroups().get(0).getOrders().get(0).setPurchaserIdcardId(78L);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 中免大会员订单，其中一个商品退款金额为0
	 * @param productBean
	 * @param goodsOwnerId
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderOneItemZeroWithCDFMember(
			AgentProductBean productBean, long goodsOwnerId) throws Exception {

		int userId = 26080783;
		
		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);
		
		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		
		orderItemVo.setSku("C052901");
		orderItemVo.setProductRecordNo("C052901");	 
		
		orderItemVo.setProductPrice(BigDecimal.ONE);
		orderItemVo.setProductNum(3);
		orderItemVo.setFreight(BigDecimal.ZERO);
		
		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.setIntegral(3L);
		placeOrderReq.setIntegralServiceType(2);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeAllPromotionOrderWithCDFMember(
			AgentProductBean productBean, long goodsOwnerId, Long integral) throws Exception {

		int userId = 26080783;
		
		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, true);
		
		OrderItemVo orderItemVo1 = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		
		orderItemVo1.setSku("C052901");
		orderItemVo1.setProductRecordNo("C052901");
		
		orderItemVo1.setProductPrice(new BigDecimal("110.00"));
		orderItemVo1.setProductNum(3);
		orderItemVo1.setFreight(BigDecimal.ZERO);
		
		OrderItemVo orderItemVo2 = TradingForDGSQCallService
				.createOrderItemVo(productBean.getProductId(), productBean
						.getCatalogList().get(1));
		
		orderItemVo2.setProductPrice(new BigDecimal("100"));
		orderItemVo2.setProductNum(3);
		orderItemVo2.setSku("C052901");
		orderItemVo2.setProductRecordNo("C052901");
		
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.getOrderItems().add(orderItemVo2);
		
//		 定义买手下的优惠商品信息list
		List<SellerPromotionVo> sellerPromotionList = new ArrayList<SellerPromotionVo>();

		SellerPromotionVo sellerPromotion1 = new SellerPromotionVo();

		sellerPromotion1.setAmountCondition(new BigDecimal(100));
		sellerPromotion1.setId(123456789);
		sellerPromotion1.setName("自动化商家优惠活动");

		sellerPromotion1.setPromotionValue(new BigDecimal(12));
		sellerPromotion1.setQtyCondition(4);

		sellerPromotion1.setReducedAmount(new BigDecimal(15));
		sellerPromotion1.setType(PromotionTypeEnum.ReduceIfAmountEnough);

		sellerPromotion1.setApportions(Arrays.asList(new CatalogApportionVo(
				orderItemVo1.getCatalogId(), orderItemVo1.getProductNum()),
				new CatalogApportionVo(orderItemVo2.getCatalogId(),
						orderItemVo2.getProductNum())));

		sellerPromotionList.add(sellerPromotion1);

		placeOrderReq.getOrderGroups().get(0)
				.setSellerPromotionApportions(sellerPromotionList);

		placeOrderReq.setIntegralServiceType(2);
		placeOrderReq.setDiscount(BigDecimal.TEN);

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.setIntegral(integral);
		placeOrderReq.setIntegralServiceType(2);
		
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setRegionDiscountRatio(new BigDecimal("9.50"));

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeOneMainOrderMultiSubOrderWithCDFMember(
			AgentProductBean productBean, long goodsOwnerId, Long integral) throws Exception {

		int userId = 26080783;
		
		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);
		
		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		
		orderItemVo.setSku("C052901");
		orderItemVo.setProductRecordNo("C052901");

		placeOrderReq.setOrderSource(OrderSourceEnum.C2CWechat);
		placeOrderReq.setIntegral(integral);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		placeOrderReq.setIntegralServiceType(2);
		
		OrderVo orderVo = TradingForDGSQCallService.createOrderVo(Arrays.asList(productBean));
		
		OrderItemVo orderItemVo2 = orderVo.getOrderItems().get(0);
		
		orderItemVo2.setSku("C052901");
		orderItemVo2.setProductRecordNo("C052901");
		
		placeOrderReq.getOrderGroups().get(0).getOrders().add(orderVo);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 代理裂变内购订单
	 * @param productBean
	 * @param goodsOwnerId
	 * @return
	 * @throws Exception
	 */
	public static TradingServiceResp placeOrderWithShenqiProxyBuyOrderForProxyFission(
			AgentProductBean productBean, long goodsOwnerId) throws Exception {

		// int userId = new OrderCallService().createNewUser();
		// int userId = 20238699;

		int userId = (int) productBean.getSellerId();

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(1234, BigDecimal.ZERO, userId,
						productBean, goodsOwnerId, false);

		placeOrderReq.getOrderGroups().get(0).setSellerId(goodsOwnerId);
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0)
				.setLogisticsType(LogisticsTypeEnum.PackageDelivery);
		
		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		
		orderItemVo.setProductId(productBean.getRootProductId());
		orderItemVo.setCatalogId(productBean.getRootCatalogList().get(0));
		orderItemVo.setProductPrice(new BigDecimal(String.valueOf(productBean
				.getAgentCatalogPriceList().get(0).getAgentPrice())));

		placeOrderReq.setShenqiProxyBuyOrder(true);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp lockCDFMemberIntegral(long cdfMembergoodsOwnerId) throws Exception {
		
		long userId = 26080783L;
		
		// 获取下单前中免大会员可用积分和冻结积分
		PointsVo pointsVo = GodPointsService.getCDFMemberUserPoints(
				cdfMembergoodsOwnerId, userId);

		Long balance = pointsVo.getBalance();

		AgentProductBean productBean = DGSQBuildProxyChainCallService
				.createProxychain((int) cdfMembergoodsOwnerId, 0, false);

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO,
						userId, productBean, (int) cdfMembergoodsOwnerId);
		
		OrderItemVo orderItemVo = placeOrderReq.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);
		orderItemVo.setProductPrice(new BigDecimal(balance.toString()).add(BigDecimal.ONE));
		orderItemVo.setProductNum(1);
		
		orderItemVo.setSku("C052901");
		orderItemVo.setProductRecordNo("C052901");
		
		placeOrderReq.setIntegral(balance);
		placeOrderReq.setIntegralServiceType(2);
		
		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static Boolean isCDFMember(Long shopId) {
		
		long cdfMembergoodsOwnerId = ShenqiUserSet.cdfMembergoodsOwnerId;
		
		if (shopId.longValue() == cdfMembergoodsOwnerId)
			return true;
		else
			return false;
	}
	
	/**
	 * 获取商户资金归集设置
	 * 
	 * @return
	 * @throws Exception 
	 */
	public static MerchantFundCollectConfigResp getMerchantFundCollectConfig(Long mchId) throws Exception {

		MerchantFundCollectConfigReq merchantFundCollectConfigReq = new MerchantFundCollectConfigReq();
		MerchantFundCollectConfigCall merchantFundCollectConfigCall = new MerchantFundCollectConfigCall();
		
		merchantFundCollectConfigReq.setMchId(mchId);
		
		merchantFundCollectConfigCall.setData(merchantFundCollectConfigReq);
		merchantFundCollectConfigCall.callService();
		
		return merchantFundCollectConfigCall.getMerchantFundCollectConfigResp();
	}
	
	/**
	 * 盛付通聚合分账job
	 * 
	 * @return
	 */
	public static void executeShengPayMerchantSharingConvergeTask() {

		YmatouEasyCall executeShengPayMerchantSharingConvergeTaskCall = new YmatouEasyCall("", "POST", "JSON");

		executeShengPayMerchantSharingConvergeTaskCall
				.setUrl("http://shenqisettlement.iapi.shop2cn.com/api/executeShengPayMerchantSharingConvergeTask");

		executeShengPayMerchantSharingConvergeTaskCall.setData("{}");

		try {
			executeShengPayMerchantSharingConvergeTaskCall.callService();

			Logger.comment(executeShengPayMerchantSharingConvergeTaskCall.getReturnData());

		} catch (Exception e) {

			e.printStackTrace();
		}
	}
	
	public static TradingServiceResp placeMultiCDFCodeOrder(
			AgentProductBean productBean, long goodsOwnerId) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO, 26080783,
						productBean, (int) goodsOwnerId);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static TradingServiceResp placeMultiCDFCodeOrderWithProductCount(
			AgentProductBean productBean, long goodsOwnerId, int productNum) throws Exception {

		PlaceOrderReq placeOrderReq = TradingForDGSQCallService
				.buildDGSQStandPlaceOrderReq(4321, BigDecimal.ZERO, 26080783,
						productBean, (int) goodsOwnerId);
		
		placeOrderReq.getOrderGroups().get(0).getOrders().get(0).getOrderItems().get(0).setProductNum(productNum);

		return TradingForDGSQCallService.callPlaceOrderService(placeOrderReq);
	}
	
	public static void main(String[] args) throws Exception {

		// TradingForDGSQCallService.getProxyChainInfo("c2285350");

		// TradingForDGSQCallService.getAllParents(500004281);

		// TradingForDGSQCallService.createKRProxychain(500072235, 1, false);

		// TradingForDGSQCallService.createNZLProxychain(500173397, 1, false);

		// TradingForDGSQCallService.createInheritedProxychain((int)
		// autotest_goodsOwnerId, false);
		// Logger.debug(TradingForDGSQCallService.isInheritedAgent(500221994));

		// Integer agentId = DGSQBaseService.createIndependenceAgent(mchId,
		// mchId, "CHN", 1);
		// DGSQBaseService.createRetailShopAgent(agentId, BigDecimal.TEN);
		// Integer agentId2 = DGSQBaseService.createIndependenceAgent(agentId,
		// mchId, "CHN", 1);
		// Integer retailShopId =
		// DGSQBaseService.createIndependenceAgent(agentId2, mchId, "CHN", 2);
		//
		// System.out.println("mchId=" + mchId + ",agentId=" + agentId +
		// ",retailShopId=" + retailShopId);

		// Integer mchId = DGSQBaseService.createIndependenceMch("USA");
		// TradingForDGSQCallService.createIndependenceProxychain(mchId, 2,
		// false, false);

//		TradingSQProductService.getProductDetails(500002490L, "p4820997");

		// Logger.debug(TradingForDGSQCallService.getMchInfoBySellerId(500325125L));

		// TradingForDGSQCallService.createWhiteMerchantProxychain(500400836,
		// false);

		// TradingForDGSQCallService.setRiskAmount(500583265, new
		// BigDecimal("10000"), new BigDecimal("20000"));

		// System.out.println(TradingForDGSQCallService.getAgentRate(500401087,
		// 500403652));

		// // 美国供货商
		// AgentProductBean productBean =
		// TradingForDGSQCallService.createSupplierProduct("USA", "CNY", false);
		//
		// Integer mchId = DGSQBaseService.createIndependenceMch("USA");
		//
		// // 创建一个新的渠道商并绑定上级
		// productBean =
		// TradingForDGSQCallService.createChannel(productBean.getSellerId(),
		// productBean.getProductId(), "HKG", (long) mchId);

		// productBean =
		// TradingForDGSQCallService.createChannel(productBean.getSellerId(),
		// productBean.getProductId(), "HKG");
		//
		// productBean =
		// TradingForDGSQCallService.createChannel(productBean.getSellerId(),
		// productBean.getProductId(), "JPN");

		// AgentProductBean japanProductBean =
		// TradingForDGSQCallService.createSupplierProduct("JPN", "CNY", false);
		//
		// TradingForDGSQCallService.createChannel(japanProductBean.getSellerId(),
		// japanProductBean.getProductId(), productBean.getCurrency(),
		// productBean.getSellerId());

		// Logger.debug(TradingForDGSQCallService.getAmountByCurrency(
		// new BigDecimal("972.00"), "CNY", "JPY"));

		// AgentProductBean productBean = new AgentProductBean();
		//
		// productBean.setSellerId(500004881);
		// productBean.setSellerLoginId("autotest500004881");
		// productBean.setProductId("p1466630");
		// productBean.setCatalogList(Lists.newArrayList("c2403528",
		// "c2403527"));
		//
		// PlaceOrderReq req =
		// TradingForDGSQCallService.buildDGSQStandPlaceOrderReq(0,
		// BigDecimal.ZERO, 20238699, productBean, autotest_goodsOwnerId);
		//
		// TradingForDGSQCallService.callPlaceOrderService(req);

		// AgentProductBean productBean = DGSQBuildProxyChainCallService
		// .createProxychain((int) autotest_goodsOwnerId, 0, false, false);
		// TradingForDGSQCallService.orderRefundFailed(productBean);
		
//		// 接单
//		TradingForDGSQCallService.sellerAcceptOrder(501720438,
//				1530013672);
//		TradingSyncService.getSyncResult(1530013672);
		
//		TradingForDGSQCallService.cancelOrder(1460027323, CancelOrderTypeEnum.SELLER_CANCEL_ORDER, 501720438L);
		
//		TradingForDGSQCallService.lockCDFMemberIntegral(500041475L);
		
		TradingForDGSQCallService.getMerchantFundCollectConfig(500041475L);

//		// 退货退款
//		HashMap<String, BigDecimal> map = RefundService.getShenqiRefundAmount(
//				1530013672L, 501720438L, "c8476722", null);
//
//		ConfirmApplyRefundReq req = RefundService.buildStandApplyRefundReq(
//				1530013672L, 501720438L, "c8476722",
//				map.get("maxRefundFreight"), map.get("maxRefundTax"),
//				map.get("maxProductRefundAmount"), null);

//		RefundService.applyRefundCall(req);
	}
}
